X-Git-Url: https://git.liburcu.org/?a=blobdiff_plain;f=src%2Fcommon%2Fformat.hpp;h=07673e7a98166ad9acd5b7d714693be9d3b9b8df;hb=830bc99366f13bfb3d6fc975441aba7388cb7ca1;hp=c1ab3d54ddc33cad2fb4a2b1c91aeab7ae2338dc;hpb=9f2636716abf0d6cc188fed380ba77a621a370c1;p=lttng-tools.git diff --git a/src/common/format.hpp b/src/common/format.hpp index c1ab3d54d..07673e7a9 100644 --- a/src/common/format.hpp +++ b/src/common/format.hpp @@ -20,6 +20,8 @@ DIAGNOSTIC_IGNORE_DUPLICATED_BRANCHES #include DIAGNOSTIC_POP +#include + /* * Due to a bug in g++ < 7.1, this specialization must be enclosed in the fmt namespace, * see https://gcc.gnu.org/bugzilla/show_bug.cgi?id=56480. @@ -32,12 +34,15 @@ struct formatter : formatter { FormatContextType& ctx) { int status; - auto demangled_name = - abi::__cxa_demangle(type_info.name(), nullptr, nullptr, &status); - auto it = status == 0 ? formatter::format(demangled_name, ctx) : - formatter::format(type_info.name(), ctx); + /* + * The documentation of __cxa_demangle mentions the returned string is allocated + * using malloc (not new), hence the use of lttng::free. + */ + const auto demangled_name = lttng::make_unique_wrapper( + abi::__cxa_demangle(type_info.name(), nullptr, nullptr, &status)); - free(demangled_name); + auto it = status == 0 ? formatter::format(demangled_name.get(), ctx) : + formatter::format(type_info.name(), ctx); return it; } };