Skip to content

Commit

Permalink
In demangle, ensure result is valid to avoid hanging. Use this util f…
Browse files Browse the repository at this point in the history
…or stacktrace logging.
  • Loading branch information
connormanning committed Oct 12, 2016
1 parent 457f5ac commit 71b3696
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
9 changes: 2 additions & 7 deletions apps/pdal.cpp
Expand Up @@ -50,7 +50,6 @@
#include <execinfo.h>
#include <unistd.h>
#include <dlfcn.h>
#include <cxxabi.h>
#endif

using namespace pdal;
Expand Down Expand Up @@ -241,8 +240,7 @@ int main(int argc, char* argv[])

if (dladdr(buffer[i], &info))
{
char* demangled = abi::__cxa_demangle(info.dli_sname, nullptr,
0, &status);
const std::string demangled(Utils::demangle(info.dli_sname));

const std::size_t offset(
static_cast<char*>(buffer[i]) -
Expand All @@ -257,11 +255,8 @@ int main(int argc, char* argv[])
prefix = symbol.substr(0, pos);
}

lines.push_back(prefix +
(status == 0 ? demangled : info.dli_sname) + " + " +
lines.push_back(prefix + demangled + " + " +
std::to_string(offset));

free(demangled);
}
else
{
Expand Down
7 changes: 4 additions & 3 deletions src/util/Utils.cpp
Expand Up @@ -537,10 +537,11 @@ std::string Utils::demangle(const std::string& s)
int status;
std::unique_ptr<char[], void (*)(void*)> result(
abi::__cxa_demangle(s.c_str(), 0, 0, &status), std::free);
return std::string(result.get());
#else
return s;
if (status == 0)
return std::string(result.get());
#endif

return s;
}


Expand Down

0 comments on commit 71b3696

Please sign in to comment.