summaryrefslogtreecommitdiff
path: root/lib/common/Utils.cpp
diff options
context:
space:
mode:
authorChris Wilson <chris+github@qwirx.com>2008-08-06 18:28:10 +0000
committerChris Wilson <chris+github@qwirx.com>2008-08-06 18:28:10 +0000
commit2cd7050a54b6db73f375c4215075b290b675bd0c (patch)
tree5f96a7d677be8e265d7d63b2a00138291c37e236 /lib/common/Utils.cpp
parent9bcf2bb465d3a200a7c5f44ed7449602fb28a4e9 (diff)
When dumping stack traces, allow libc to allocate its own memory, rather
than trying to manage a buffer ourselves, and free it with std::free without memory leak tracing.
Diffstat (limited to 'lib/common/Utils.cpp')
-rw-r--r--lib/common/Utils.cpp28
1 files changed, 11 insertions, 17 deletions
diff --git a/lib/common/Utils.cpp b/lib/common/Utils.cpp
index 972a817d..b2a16d5b 100644
--- a/lib/common/Utils.cpp
+++ b/lib/common/Utils.cpp
@@ -68,20 +68,13 @@ void SplitString(const std::string &String, char SplitOn, std::vector<std::strin
#ifdef SHOW_BACKTRACE_ON_EXCEPTION
void DumpStackBacktrace()
{
- void *array[10];
- size_t size;
- char **strings;
- size_t i;
-
- size = backtrace (array, 10);
- strings = backtrace_symbols (array, size);
+ void *array[10];
+ size_t size = backtrace (array, 10);
+ char **strings = backtrace_symbols (array, size);
BOX_TRACE("Obtained " << size << " stack frames.");
- size_t output_len = 256;
- char* output_buf = new char [output_len];
-
- for(i = 0; i < size; i++)
+ for(size_t i = 0; i < size; i++)
{
// Demangling code copied from
// cctbx_sources/boost_adaptbx/meta_ext.cpp, BSD license
@@ -97,8 +90,10 @@ void DumpStackBacktrace()
int status;
+#include "MemLeakFindOff.h"
char* result = abi::__cxa_demangle(mangled_func.c_str(),
- output_buf, &output_len, &status);
+ NULL, NULL, &status);
+#include "MemLeakFindOn.h"
if (result == NULL)
{
@@ -137,20 +132,19 @@ void DumpStackBacktrace()
}
else
{
- output_buf = result;
output_frame = mangled_frame.substr(0, start + 1) +
- // std::string(output_buf.get()) +
result + mangled_frame.substr(end);
+#include "MemLeakFindOff.h"
+ std::free(result);
+#include "MemLeakFindOn.h"
}
#endif // HAVE_CXXABI_H
BOX_TRACE("Stack frame " << i << ": " << output_frame);
}
- delete [] output_buf;
-
#include "MemLeakFindOff.h"
- free (strings);
+ std::free (strings);
#include "MemLeakFindOn.h"
}
#endif