Commit c338a2e8 authored by Neverlord's avatar Neverlord

use smart pointer to store result of demangling

parent e512567a
...@@ -44,7 +44,10 @@ namespace cppa { namespace detail { ...@@ -44,7 +44,10 @@ namespace cppa { namespace detail {
std::string demangle(const char* decorated) { std::string demangle(const char* decorated) {
size_t size; size_t size;
int status; int status;
char* undecorated = abi::__cxa_demangle(decorated, nullptr, &size, &status); std::unique_ptr<char, void (*)(void*)> undecorated{
abi::__cxa_demangle(decorated, nullptr, &size, &status),
std::free
};
if (status != 0) { if (status != 0) {
std::string error_msg = "Could not demangle type name "; std::string error_msg = "Could not demangle type name ";
error_msg += decorated; error_msg += decorated;
...@@ -52,7 +55,7 @@ std::string demangle(const char* decorated) { ...@@ -52,7 +55,7 @@ std::string demangle(const char* decorated) {
} }
std::string result; // the undecorated typeid name std::string result; // the undecorated typeid name
result.reserve(size); result.reserve(size);
const char* cstr = undecorated; const char* cstr = undecorated.get();
// filter unnecessary characters from undecorated // filter unnecessary characters from undecorated
char c = *cstr; char c = *cstr;
while (c != '\0') { while (c != '\0') {
...@@ -78,7 +81,6 @@ std::string demangle(const char* decorated) { ...@@ -78,7 +81,6 @@ std::string demangle(const char* decorated) {
c = *++cstr; c = *++cstr;
} }
} }
free(undecorated);
# ifdef CPPA_CLANG # ifdef CPPA_CLANG
// replace "std::__1::" with "std::" (fixes strange clang names) // replace "std::__1::" with "std::" (fixes strange clang names)
std::string needle = "std::__1::"; std::string needle = "std::__1::";
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment