-
Notifications
You must be signed in to change notification settings - Fork 34
spindle_logd does not delete heap allocations #171
Copy link
Copy link
Open
Description
Bug:
MsgReader allocates a new connection onto the heap but delete is never called on the connection
Allocation:
Spindle/src/logging/spindle_logd.cc
Line 408 in 585dacf
| Connection *con = new Connection(); |
Connection cleanup
Only removes the connection from the map:
Spindle/src/logging/spindle_logd.cc
Lines 476 to 478 in 585dacf
| 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:
Spindle/src/logging/spindle_logd.cc
Lines 594 to 600 in 585dacf
| ~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>();
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels