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

subversion at boxbackup.org subversion at boxbackup.org
Tue Feb 11 10:29:25 GMT 2014


Author: chris
Date: 2014-02-11 10:29:25 +0000 (Tue, 11 Feb 2014)
New Revision: 3256

Modified:
   box/trunk/lib/common/Utils.cpp
Log:
Simplify C++ name demangling code, and its memory allocation tracking.

Modified: box/trunk/lib/common/Utils.cpp
===================================================================
--- box/trunk/lib/common/Utils.cpp	2014-02-11 10:29:20 UTC (rev 3255)
+++ box/trunk/lib/common/Utils.cpp	2014-02-11 10:29:25 UTC (rev 3256)
@@ -83,62 +83,50 @@
 #ifdef SHOW_BACKTRACE_ON_EXCEPTION
 static std::string demangle(const std::string& mangled_name)
 {
+	std::string demangled_name = mangled_name;
+
 	#ifdef HAVE_CXXABI_H
+	char buffer[1024];
 	int status;
+	size_t length = sizeof(buffer);
 	
-#include "MemLeakFindOff.h"
 	char* result = abi::__cxa_demangle(mangled_name.c_str(),
-		NULL, NULL, &status);
-#include "MemLeakFindOn.h"
+		buffer, &length, &status);
 
-	if (result == NULL)
+	if (status == 0)
 	{
-		if (status == 0)
-		{
-			BOX_WARNING("Demangle failed but no error: " <<
-				mangled_name);
-		}
-		else if (status == -1)
-		{
-			BOX_WARNING("Demangle failed with "
-				"memory allocation error: " <<
-				mangled_name);
-		}
-		else if (status == -2)
-		{
-			// Probably non-C++ name, don't demangle
-			/*
-			BOX_WARNING("Demangle failed with "
-				"with invalid name: " <<
-				mangled_name);
-			*/
-		}
-		else if (status == -3)
-		{
-			BOX_WARNING("Demangle failed with "
-				"with invalid argument: " <<
-				mangled_name);
-		}
-		else
-		{
-			BOX_WARNING("Demangle failed with "
-				"with unknown error " << status <<
-				": " << mangled_name);
-		}
-
-		return std::string(mangled_name);
+		demangled_name = result;
 	}
+	else if (status == -1)
+	{
+		BOX_WARNING("Demangle failed with "
+			"memory allocation error: " <<
+			mangled_name);
+	}
+	else if (status == -2)
+	{
+		// Probably non-C++ name, don't demangle
+		/*
+		BOX_WARNING("Demangle failed with "
+			"with invalid name: " <<
+			mangled_name);
+		*/
+	}
+	else if (status == -3)
+	{
+		BOX_WARNING("Demangle failed with "
+			"with invalid argument: " <<
+			mangled_name);
+	}
 	else
 	{
-		std::string output = result;
-#include "MemLeakFindOff.h"
-		free(result);
-#include "MemLeakFindOn.h"
-		return output;
+		BOX_WARNING("Demangle failed with "
+			"with unknown error " << status <<
+			": " << mangled_name);
 	}
-	#else // !HAVE_CXXABI_H
-	return mangled_name;
 	#endif // HAVE_CXXABI_H
+
+	return demangled_name;
 }
 
 void DumpStackBacktrace()




More information about the Boxbackup-commit mailing list