Skip to content

Commit

Permalink
Fix several resource leaks (#1435)
Browse files Browse the repository at this point in the history
* Local var leak in Symtab::addSymbol

This was found using cppcheck's memleak.

* memCache::doOperation

Not technically a leak, but cppcheck can't see through the 'push_back'.

* PCProcess::hasPassedMain

Found using cppcheck's danglingTemporaryLifetime.

* parse_func::calcParentFunc

Found using cppcheck's danglingTemporaryLifetime.

* int_iRPC::setBinarySize

Found using cppcheck's publicAllocationError.
  • Loading branch information
hainest committed May 11, 2023
1 parent 8676f10 commit 44d86e5
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 8 deletions.
3 changes: 2 additions & 1 deletion dyninstAPI/src/parse-power.C
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ std::string parse_func::calcParentFunc(const parse_func * imf,
/* We need to figure out the function that called the outlined
parallel region function. We do this by chopping off the
last @OL@number */
const char * nameStart = imf->prettyName().c_str();
auto const& tmp = imf->prettyName();
const char * nameStart = tmp.c_str();
const char * nameEnd = strrchr(nameStart, '@');
int strSize = nameEnd - nameStart - 3;

Expand Down
3 changes: 2 additions & 1 deletion dyninstAPI/src/unix.C
Original file line number Diff line number Diff line change
Expand Up @@ -530,11 +530,12 @@ bool PCProcess::hasPassedMain()
bool PCProcess::startDebugger() {
std::stringstream pidStr;
pidStr << getPid();
auto tmp = pidStr.str();

const char *args[4];
args[0] = dyn_debug_crash_debugger;
args[1] = file_.c_str();
args[2] = pidStr.str().c_str();
args[2] = tmp.c_str();
args[3] = NULL;

proccontrol_printf("%s[%d]: Launching %s %s %s\n", FILE__, __LINE__,
Expand Down
1 change: 1 addition & 0 deletions proccontrol/src/irpc.C
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ void int_iRPC::setBinarySize(unsigned long s)

void int_iRPC::copyBinaryBlob(void *b, unsigned long s)
{
if(binary_blob && freeBinaryBlob) free(binary_blob);
binary_blob = malloc(s);
assert(binary_blob);
binary_size = s;
Expand Down
4 changes: 1 addition & 3 deletions proccontrol/src/memcache.C
Original file line number Diff line number Diff line change
Expand Up @@ -301,9 +301,7 @@ async_ret_t memCache::doOperation(memEntry *me, int_thread *op_thread)
return aret_error;
}

memEntry *me_copy = new memEntry(me, me->buffer);

mem_cache.push_back(me_copy);
mem_cache.push_back(new memEntry(me, me->buffer));
last_operation = mem_cache.end();
last_operation--;

Expand Down
6 changes: 3 additions & 3 deletions symtabAPI/src/Symtab-edit.C
Original file line number Diff line number Diff line change
Expand Up @@ -244,15 +244,15 @@ bool Symtab::addSymbol(Symbol *newSym, Symbol *referringSymbol)
newSym->setReferringSymbol(referringSymbol);

string filename = referringSymbol->getModule()->exec()->name();
vector<string> *vers, *newSymVers = new vector<string>;
vector<string> *vers{};
newSym->setVersionFileName(filename);
std::string rstr;

newSym->getVersionFileName(rstr);
if (referringSymbol->getVersions(vers) && vers != NULL && vers->size() > 0)
{
newSymVers->push_back((*vers)[0]);
newSym->setVersions(*newSymVers);
auto newSymVers = std::vector<std::string>{(*vers)[0]};
newSym->setVersions(newSymVers);
}
}else{
newSym->setReferringSymbol(referringSymbol);
Expand Down

0 comments on commit 44d86e5

Please sign in to comment.