Changeset 2221

Show
Ignore:
Timestamp:
06/08/2008 19:28:10 (5 months ago)
Author:
chris
Message:

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.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • box/trunk/lib/common/Utils.cpp

    r2187 r2221  
    6969void DumpStackBacktrace() 
    7070{ 
    71         void *array[10]; 
    72         size_t size; 
    73         char **strings; 
    74         size_t i; 
    75  
    76         size = backtrace (array, 10); 
    77         strings = backtrace_symbols (array, size); 
     71        void  *array[10]; 
     72        size_t size = backtrace (array, 10); 
     73        char **strings = backtrace_symbols (array, size); 
    7874 
    7975        BOX_TRACE("Obtained " << size << " stack frames."); 
    8076 
    81         size_t output_len = 256; 
    82         char*  output_buf = new char [output_len]; 
    83  
    84         for(i = 0; i < size; i++) 
     77        for(size_t i = 0; i < size; i++) 
    8578        { 
    8679                // Demangling code copied from  
     
    9891                int status; 
    9992                 
     93#include "MemLeakFindOff.h" 
    10094                char* result = abi::__cxa_demangle(mangled_func.c_str(), 
    101                         output_buf, &output_len, &status); 
     95                        NULL, NULL, &status); 
     96#include "MemLeakFindOn.h" 
    10297 
    10398                if (result == NULL) 
     
    138133                else 
    139134                { 
    140                         output_buf = result; 
    141135                        output_frame = mangled_frame.substr(0, start + 1) + 
    142                                 // std::string(output_buf.get()) + 
    143136                                result + mangled_frame.substr(end); 
     137#include "MemLeakFindOff.h" 
     138                        std::free(result); 
     139#include "MemLeakFindOn.h" 
    144140                } 
    145141                #endif // HAVE_CXXABI_H 
     
    148144        } 
    149145 
    150         delete [] output_buf; 
    151  
    152146#include "MemLeakFindOff.h" 
    153         free (strings); 
     147        std::free (strings); 
    154148#include "MemLeakFindOn.h" 
    155149}