Skip to content

Commit

Permalink
SymElf: fix memory leak of cached demangled names
Browse files Browse the repository at this point in the history
* the existing cache in SymElf did not free the char* string in each
  cache entry
  • Loading branch information
kupsch committed Oct 21, 2020
1 parent fd520f7 commit 464b24e
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions symlite/src/SymLite-elf.C
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,11 @@ SymElf::~SymElf()
fd = -1;
}
if (cache) {
for (unsigned int i = 0; i < cache_size; ++i) {
if (cache[i].demangled_name) {
free(const_cast<char*>(cache[i].demangled_name));
}
}
free(cache);
cache = NULL;
cache_size = 0;
Expand Down Expand Up @@ -366,9 +371,8 @@ std::string SymElf::getDemangledName(const Symbol_t &sym)

if (cache[cache_index].demangled_name)
return std::string(cache[cache_index].demangled_name);
//char *res = P_cplus_demangle(name, true);
std::string res = P_cplus_demangle(name, true);

std::string res = P_cplus_demangle(name, true);
cache[cache_index].demangled_name = strdup(res.c_str());
return cache[cache_index].demangled_name;
}
Expand Down

0 comments on commit 464b24e

Please sign in to comment.