From e5551befe8caf1eea0e2f01006dfb193667b3af2 Mon Sep 17 00:00:00 2001 From: Mark Johnston Date: Tue, 4 Feb 2020 21:14:53 +0000 Subject: [PATCH] libdwarf: Fix a possible memory leak in dwarf_add_AT_location_expr(). CID: 1193364 MFC after: 1 week Sponsored by: The FreeBSD Foundation --- contrib/elftoolchain/libdwarf/dwarf_pro_attr.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/contrib/elftoolchain/libdwarf/dwarf_pro_attr.c b/contrib/elftoolchain/libdwarf/dwarf_pro_attr.c index f46672bba504..6d5fb4d687b2 100644 --- a/contrib/elftoolchain/libdwarf/dwarf_pro_attr.c +++ b/contrib/elftoolchain/libdwarf/dwarf_pro_attr.c @@ -46,8 +46,10 @@ dwarf_add_AT_location_expr(Dwarf_P_Debug dbg, Dwarf_P_Die die, Dwarf_Half attr, at->at_attrib = attr; at->at_expr = loc_expr; - if (_dwarf_expr_into_block(loc_expr, error) != DW_DLE_NONE) + if (_dwarf_expr_into_block(loc_expr, error) != DW_DLE_NONE) { + free(at); return (DW_DLV_BADADDR); + } at->u[0].u64 = loc_expr->pe_length; at->u[1].u8p = loc_expr->pe_block; if (loc_expr->pe_length <= UCHAR_MAX)