From 0f990f05a1617d835530f1fa44b516343f4409db Mon Sep 17 00:00:00 2001 From: Jeremy Rifkin <51220084+jeremy-rifkin@users.noreply.github.com> Date: Mon, 17 Feb 2025 01:01:42 -0600 Subject: [PATCH] Use raii_wrap for dwarf_dealloc_error in handle_dwarf_error --- src/symbols/dwarf/dwarf.hpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/symbols/dwarf/dwarf.hpp b/src/symbols/dwarf/dwarf.hpp index 7d60948..835a7f9 100644 --- a/src/symbols/dwarf/dwarf.hpp +++ b/src/symbols/dwarf/dwarf.hpp @@ -27,11 +27,9 @@ namespace libdwarf { [[noreturn]] inline void handle_dwarf_error(Dwarf_Debug dbg, Dwarf_Error error) { Dwarf_Unsigned ev = dwarf_errno(error); - const char* msg = dwarf_errmsg(error); - // dwarf_dealloc_error deallocates the message - auto error_message = microfmt::format("dwarf error {} {}", ev, msg); - dwarf_dealloc_error(dbg, error); - throw internal_error(std::move(error_message)); + // dwarf_dealloc_error deallocates the message, attaching to msg is convenient + auto msg = raii_wrap(dwarf_errmsg(error), [dbg, error] (char*) { dwarf_dealloc_error(dbg, error); }); + throw internal_error(microfmt::format("dwarf error {} {}", ev, msg.get())); } struct die_object {