Changeset 2187


Ignore:
Timestamp:
28/05/2008 18:04:18 (4 years ago)
Author:
chris
Message:

Fix possible memory corruption while dumping stack trace due to
mismatching new []/delete.

File:
1 edited

Legend:

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

    r2178 r2187  
    7878 
    7979        BOX_TRACE("Obtained " << size << " stack frames."); 
     80 
     81        size_t output_len = 256; 
     82        char*  output_buf = new char [output_len]; 
    8083 
    8184        for(i = 0; i < size; i++) 
     
    9396                        end - start - 1); 
    9497 
    95                 size_t len = 256; 
    96                 std::auto_ptr<char> output_buf(new char [len]); 
    9798                int status; 
    9899                 
    99                 if (abi::__cxa_demangle(mangled_func.c_str(), output_buf.get(), 
    100                         &len, &status) == NULL) 
     100                char* result = abi::__cxa_demangle(mangled_func.c_str(), 
     101                        output_buf, &output_len, &status); 
     102 
     103                if (result == NULL) 
    101104                { 
    102105                        if (status == 0) 
     
    113116                        else if (status == -2) 
    114117                        { 
     118                                // Probably non-C++ name, don't demangle 
    115119                                /* 
    116120                                BOX_WARNING("Demangle failed with " 
     
    134138                else 
    135139                { 
     140                        output_buf = result; 
    136141                        output_frame = mangled_frame.substr(0, start + 1) + 
    137142                                // std::string(output_buf.get()) + 
    138                                 output_buf.get() + 
    139                                 mangled_frame.substr(end); 
     143                                result + mangled_frame.substr(end); 
    140144                } 
    141145                #endif // HAVE_CXXABI_H 
     
    143147                BOX_TRACE("Stack frame " << i << ": " << output_frame); 
    144148        } 
     149 
     150        delete [] output_buf; 
    145151 
    146152#include "MemLeakFindOff.h" 
Note: See TracChangeset for help on using the changeset viewer.