Skip to content

Commit e323378

Browse files
committed
Further work to address copy assignment memory leak.
1 parent a9ac410 commit e323378

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1010

1111
### Changed
1212
- Change 266 files from CRLF to LF.
13+
- Apply "rule of three" to Client copy constructor and copy assignment operator
1314

1415
### Deprecated
1516

cpp/arduino/Client.h

+6-4
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,18 @@ class Client : public Stream {
1313
}
1414
Client(const Client &client) { // copy constructor
1515
if (this != &client) { // not a self-assignment
16-
if (mGodmodeDataIn) { // replace what we previously had
17-
delete mGodmodeDataIn; // get rid of previous value
16+
if (mGodmodeDataIn &&
17+
client.mGodmodeDataIn) { // replace what we previously had
18+
delete mGodmodeDataIn; // get rid of previous value
1819
mGodmodeDataIn = new String(client.mGodmodeDataIn->c_str());
1920
}
2021
}
2122
}
2223
Client &operator=(const Client &client) { // copy assignment operator
2324
if (this != &client) { // not a self-assignment
24-
if (mGodmodeDataIn) { // replace what we previously had
25-
delete mGodmodeDataIn; // get rid of previous value
25+
if (mGodmodeDataIn &&
26+
client.mGodmodeDataIn) { // replace what we previously had
27+
delete mGodmodeDataIn; // get rid of previous value
2628
mGodmodeDataIn = new String(client.mGodmodeDataIn->c_str());
2729
}
2830
}

0 commit comments

Comments
 (0)