Skip to content

spindle_logd does not delete heap allocations #171

@SamHerts

Description

@SamHerts

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>();

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions