Skip to content

Commit 112a47e

Browse files
authored
Merge pull request #481 from jonesmz/fix-virtual-destructor-warning
Fixes #458
2 parents e9d7099 + c5023e7 commit 112a47e

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

include/mqtt/async_client.hpp

+6
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,12 @@ class async_client : public client<Socket, PacketIdBytes> {
251251
void unsuback() = delete;
252252

253253
protected:
254+
// Ensure that only code that knows the *exact* type of an object
255+
// inheriting from this abstract base class can destruct it.
256+
// This avoids issues of the destructor not triggering destruction
257+
// of derived classes, and any member variables contained in them.
258+
// Note: Not virtual to avoid need for a vtable when possible.
259+
~async_client() = default;
254260

255261
async_client(
256262
as::io_context& ioc,

include/mqtt/client.hpp

+8
Original file line numberDiff line numberDiff line change
@@ -927,6 +927,14 @@ class client : public endpoint<std::mutex, std::lock_guard, PacketIdBytes> {
927927
if (ping_duration_ms_ != 0) tim_ping_.cancel();
928928
}
929929

930+
protected:
931+
// Ensure that only code that knows the *exact* type of an object
932+
// inheriting from this abstract base class can destruct it.
933+
// This avoids issues of the destructor not triggering destruction
934+
// of derived classes, and any member variables contained in them.
935+
// Note: Not virtual to avoid need for a vtable when possible.
936+
~client() = default;
937+
930938
private:
931939
std::shared_ptr<Socket> socket_;
932940
as::io_context& ioc_;

include/mqtt/sync_client.hpp

+6
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,12 @@ class sync_client : public client<Socket, PacketIdBytes> {
250250
void async_unsuback() = delete;
251251

252252
protected:
253+
// Ensure that only code that knows the *exact* type of an object
254+
// inheriting from this abstract base class can destruct it.
255+
// This avoids issues of the destructor not triggering destruction
256+
// of derived classes, and any member variables contained in them.
257+
// Note: Not virtual to avoid need for a vtable when possible.
258+
~sync_client() = default;
253259

254260
sync_client(
255261
as::io_context& ioc,

0 commit comments

Comments
 (0)