Skip to content

Commit

Permalink
fixed memory leak
Browse files Browse the repository at this point in the history
  • Loading branch information
orignal committed Jan 13, 2014
1 parent 9b92641 commit 34d2ae4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
4 changes: 3 additions & 1 deletion LeaseSet.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ namespace data
public:

LeaseSet (const uint8_t * buf, int len);

LeaseSet (const LeaseSet& ) = default;
LeaseSet& operator=(const LeaseSet& ) = default;

// implements RoutingDestination
const Identity& GetIdentity () const { return m_Identity; };
const IdentHash& GetIdentHash () const { return m_IdentHash; };
Expand Down
20 changes: 15 additions & 5 deletions NetDb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,9 @@ namespace data
if (r->GetTimestamp () > it->second->GetTimestamp ())
{
LogPrint ("RouterInfo updated");
*m_RouterInfos[r->GetIdentHash ()] = *r; // we can't replace point because it's used by tunnels
}
else
delete r;
*(it->second) = *r; // we can't replace pointer because it's used by tunnels
}
delete r;
}
else
{
Expand All @@ -135,7 +134,18 @@ namespace data
{
LeaseSet * l = new LeaseSet (buf, len);
DeleteRequestedDestination (l->GetIdentHash ());
m_LeaseSets[l->GetIdentHash ()] = l;
auto it = m_LeaseSets.find(l->GetIdentHash ());
if (it != m_LeaseSets.end ())
{
LogPrint ("LeaseSet updated");
*(it->second) = *l; // we can't replace pointer because it's used by streams
delete l;
}
else
{
LogPrint ("New LeaseSet added");
m_LeaseSets[l->GetIdentHash ()] = l;
}
}

RouterInfo * NetDb::FindRouter (const IdentHash& ident) const
Expand Down

0 comments on commit 34d2ae4

Please sign in to comment.