Skip to content

Commit

Permalink
more leak fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
pefoley2 committed Nov 25, 2016
1 parent 87eff36 commit c88e442
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 6 deletions.
1 change: 1 addition & 0 deletions dyninstAPI/h/BPatch_type.h
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ class BPATCH_DLL_EXPORT BPatch_type{

// INTERNAL DATA MEMBERS

bool owns_typ;
unsigned int refCount;

protected:
Expand Down
13 changes: 9 additions & 4 deletions dyninstAPI/src/BPatch.C
Original file line number Diff line number Diff line change
Expand Up @@ -165,14 +165,19 @@ BPatch::BPatch()

stdTypes = BPatch_typeCollection::getGlobalTypeCollection();
vector<Type *> *sTypes = Symtab::getAllstdTypes();
for(unsigned i=0; i< sTypes->size(); i++)
stdTypes->addType(new BPatch_type((*sTypes)[i]));
BPatch_type* type = NULL;
for(const auto& t: *sTypes) {
stdTypes->addType(type = new BPatch_type(t));
type->decrRefCount();
}
delete sTypes;

builtInTypes = new BPatch_builtInTypeCollection;
sTypes = Symtab::getAllbuiltInTypes();
for(unsigned i=0; i< sTypes->size(); i++)
builtInTypes->addBuiltInType(new BPatch_type((*sTypes)[i]));
for(const auto& t: *sTypes) {
builtInTypes->addBuiltInType(type = new BPatch_type(t));
type->decrRefCount();
}
delete sTypes;

//loadNativeDemangler();
Expand Down
8 changes: 8 additions & 0 deletions dyninstAPI/src/BPatch_collections.C
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,14 @@ BPatch_typeCollection::~BPatch_typeCollection()
// decRefCount (which will delete when refcount == 0)
assert(refcount == 0 ||
refcount == 1);

for(const auto& t: typesByName) {
t.second->decrRefCount();
}

for(const auto& t: typesByID) {
t.second->decrRefCount();
}
}

/*
Expand Down
7 changes: 5 additions & 2 deletions dyninstAPI/src/BPatch_type.C
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ BPatch_type *BPatch_type::createFake(const char *_name) {
*
*/

BPatch_type::BPatch_type(Type *typ_): ID(typ_->getID()), typ(typ_),
BPatch_type::BPatch_type(Type *typ_): ID(typ_->getID()), typ(typ_), owns_typ(false),
refCount(1)
{
// if a derived type, make sure the upPtr is set for the base type.
Expand Down Expand Up @@ -117,7 +117,7 @@ BPatch_type::BPatch_type(Type *typ_): ID(typ_->getID()), typ(typ_),
}

BPatch_type::BPatch_type(const char *_name, int _ID, BPatch_dataClass _type) :
ID(_ID), type_(_type), typ(NULL), refCount(1)
ID(_ID), type_(_type), typ(NULL), owns_typ(true), refCount(1)
{
if (_name != NULL)
typ = new Type(_name, ID, convertToSymtabType(_type));
Expand Down Expand Up @@ -147,6 +147,9 @@ BPatch_type *BPatch_type::findOrCreateType(Dyninst::SymtabAPI::Type *type)
*/
BPatch_type::~BPatch_type()
{
if(owns_typ) {
typ->decrRefCount();
}
}

bool BPatch_type::operator==(const BPatch_type &otype) const
Expand Down

0 comments on commit c88e442

Please sign in to comment.