Bug:
MsgReader allocates a new connection onto the heap but delete is never called on the connection
Allocation:
|
Connection *con = new Connection(); |
Connection cleanup
Only removes the connection from the map:
|
for (std::map<int, Connection *>::iterator i = conns.begin(); i != conns.end(); i++) { |
|
if (i->second->shutdown) { |
|
conns.erase(i); |
Only closes the file descriptor and clears the map:
|
~MsgReader() |
|
{ |
|
for (std::map<int, Connection *>::iterator i = conns.begin(); i != conns.end(); i++) { |
|
int fd = i->first; |
|
close(fd); |
|
} |
|
conns.clear(); |
Fix:
Two options:
for (std::map<int, Connection *>::iterator i = conns.begin(); i != conns.end(); i++) {
if (i->second->shutdown) {
delete i->second;
conns.erase(i);
~MsgReader()
{
for (std::map<int, Connection *>::iterator i = conns.begin(); i != conns.end(); i++) {
int fd = i->first;
close(fd);
delete i->second;
}
conns.clear();
Or swap to an std::unique_ptr:
std::map<int, std::unique_ptr<Connection>> conns;
...
Connection *con = std::make_unique<Connection>();
Bug:
MsgReaderallocates a new connection onto the heap but delete is never called on the connectionAllocation:
Spindle/src/logging/spindle_logd.cc
Line 408 in 585dacf
Connection cleanup
Only removes the connection from the map:
Spindle/src/logging/spindle_logd.cc
Lines 476 to 478 in 585dacf
Only closes the file descriptor and clears the map:
Spindle/src/logging/spindle_logd.cc
Lines 594 to 600 in 585dacf
Fix:
Two options:
Or swap to an
std::unique_ptr: