[Box Backup-commit] COMMIT r2221 - box/trunk/lib/common

boxbackup-dev at fluffy.co.uk boxbackup-dev at fluffy.co.uk
Wed Aug 6 19:28:11 BST 2008


Author: chris
Date: 2008-08-06 19:28:10 +0100 (Wed, 06 Aug 2008)
New Revision: 2221

Modified:
   box/trunk/lib/common/Utils.cpp
Log:
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.


Modified: box/trunk/lib/common/Utils.cpp
===================================================================
--- box/trunk/lib/common/Utils.cpp	2008-08-06 18:25:48 UTC (rev 2220)
+++ box/trunk/lib/common/Utils.cpp	2008-08-06 18:28:10 UTC (rev 2221)
@@ -68,20 +68,13 @@
 #ifdef SHOW_BACKTRACE_ON_EXCEPTION
 void DumpStackBacktrace()
 {
-	void *array[10];
-	size_t size;
-	char **strings;
-	size_t i;
+	void  *array[10];
+	size_t size = backtrace (array, 10);
+	char **strings = backtrace_symbols (array, size);
 
-	size = backtrace (array, 10);
-	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 @@
 
 		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 @@
 		}
 		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




More information about the Boxbackup-commit mailing list