Use raii_wrap for dwarf_dealloc_error in handle_dwarf_error

This commit is contained in:
Jeremy Rifkin 2025-02-17 01:01:42 -06:00
parent 4ab78f7a69
commit 0f990f05a1
No known key found for this signature in database
GPG Key ID: 19AA8270105E8EB4

View File

@ -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 {