Skip to content

Commit

Permalink
Remove CFGFactor::destroy_all (#881)
Browse files Browse the repository at this point in the history
This removes the possiblity of object reuse and its associated undefined
behavior. This was originally part of #317.
  • Loading branch information
hainest committed Oct 21, 2020
1 parent c0efad5 commit 0d14ca1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 26 deletions.
2 changes: 0 additions & 2 deletions parseAPI/h/CFGFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,6 @@ class PARSER_EXPORT CFGFactory {
void destroy_block(Block *b);
void destroy_edge(Edge *e, EdgeState reason);

void destroy_all();

protected:
virtual Function * mkfunc(Address addr, FuncSource src,
std::string name, CodeObject * obj, CodeRegion * region,
Expand Down
33 changes: 9 additions & 24 deletions parseAPI/src/CFGFactory.C
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,15 @@ Edge::Edge(Block *source, Block *target, EdgeTypeEnum type)

CFGFactory::~CFGFactory()
{
destroy_all();
for(Edge *e : edges_) {
destroy_edge(e, destroyed_all);
}
for(Block *b : blocks_) {
destroy_block(b);
}
for(Function *f : funcs_) {
destroy_func(f);
}
}

// ParseAPI call...
Expand Down Expand Up @@ -202,26 +210,3 @@ void
CFGFactory::free_edge(Edge *e) {
delete e;
}

void
CFGFactory::destroy_all() {
// XXX carefully calling free_* routines; could be faster and just
// call delete

fact_list<Edge *>::iterator eit = edges_.begin();
while(eit != edges_.end()) {
fact_list<Edge *>::iterator cur = eit++;
destroy_edge(*cur, destroyed_all);
}
fact_list<Block *>::iterator bit = blocks_.begin();
while(bit != blocks_.end()) {
fact_list<Block *>::iterator cur = bit++;
destroy_block(*cur);
}
fact_list<Function *>::iterator fit = funcs_.begin();
while(fit != funcs_.end()) {
fact_list<Function *>::iterator cur = fit++;
destroy_func(*cur);
}
}

0 comments on commit 0d14ca1

Please sign in to comment.