Skip to content

Commit fc34a08

Browse files
authored
Merge pull request #1 from DennisPurdack/libmodbuspp-ascii-support
(re-)added virtual destructors to prevent memory leaks
2 parents a81892c + 8125121 commit fc34a08

File tree

11 files changed

+16
-3
lines changed

11 files changed

+16
-3
lines changed

include/modbuspp/asciilayer.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@ namespace Modbus {
4646
*/
4747
AsciiLayer (const std::string & port, const std::string & settings);
4848

49+
/**
50+
* @brief Destructor
51+
*/
52+
virtual ~AsciiLayer() = default;
53+
4954
/**
5055
* @brief Name of the serial port
5156
*

src/asciilayer_p.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ namespace Modbus {
2525

2626
public:
2727
Private (const std::string & port, const std::string & settings);
28+
virtual ~Private() = default;
2829

2930
int oneByteTime;
3031
};

src/device_p.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ namespace Modbus {
2828

2929
public:
3030
Private (Device * q);
31+
virtual ~Private() = default;
3132
virtual void setBackend (Net net, const std::string & connection,
3233
const std::string & settings);
3334
virtual void setConfig (const nlohmann::json & config);

src/master_p.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ namespace Modbus {
2626

2727
public:
2828
Private (Master * q);
29+
virtual ~Private() = default;
2930

3031
void setBackend (Net net, const std::string & connection,
3132
const std::string & settings) override;
@@ -39,4 +40,3 @@ namespace Modbus {
3940
}
4041

4142
/* ========================================================================== */
42-

src/netlayer_p.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ namespace Modbus {
2424
public:
2525
Private (Net n, const std::string & c, const std::string & s, uint16_t m) :
2626
net (n), connection (c), settings (s), maxAduLength (m) {}
27+
virtual ~Private() = default;
2728

2829
Net net;
2930
std::string connection;

src/router_p.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ namespace Modbus {
2525

2626
public:
2727
Private (Router * q);
28+
virtual ~Private() = default;
2829
virtual void setConfig (const nlohmann::json & config);
2930

3031
virtual bool open();

src/rtulayer_p.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ namespace Modbus {
2525

2626
public:
2727
Private (const std::string & port, const std::string & settings);
28+
virtual ~Private() = default;
2829

2930
int oneByteTime;
3031
};

src/server.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,7 @@ namespace Modbus {
496496

497497
// ---------------------------------------------------------------------------
498498
// static
499-
void * Server::Private::loop (std::future<void> run, Private * d) {
499+
void Server::Private::loop (std::future<void> run, Private * d) {
500500
int rc;
501501

502502
while (run.wait_for (std::chrono::milliseconds (100)) == std::future_status::timeout) {

src/server_p.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ namespace Modbus {
3030
static const int MAX_CONNECTIONS = 16;
3131
public:
3232
Private (Server * q);
33+
virtual ~Private() = default;
3334
virtual void setBackend (Net net, const std::string & connection,
3435
const std::string & settings);
3536
virtual void setConfig (const nlohmann::json & config);
@@ -41,7 +42,7 @@ namespace Modbus {
4142

4243
BufferedSlave * addSlave (int slaveAddr, Device * master);
4344

44-
static void * loop (std::future<void> run, Private * d);
45+
static void loop (std::future<void> run, Private * d);
4546
static int receive (Private * d);
4647

4748
int listen_sock = -1;

src/slave_p.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ namespace Modbus {
2828
public:
2929
Private (Slave * q);
3030
Private (Slave * q, int s, Device * d);
31+
virtual ~Private() = default;
3132

3233
inline modbus_t * ctx() {
3334
return dev->backend().context();

0 commit comments

Comments
 (0)