https://sourceware.org/bugzilla/show_bug.cgi?id=29434
Bug ID: 29434 Summary: Memory leak in `dwarf_getscopes` Product: elfutils Version: unspecified Status: UNCONFIRMED Severity: normal Priority: P2 Component: libdw Assignee: unassigned at sourceware dot org Reporter: godlygeek at gmail dot com CC: elfutils-devel at sourceware dot org Target Milestone: --- Found by valgrind: ==173857== 64 bytes in 2 blocks are definitely lost in loss record 3,155 of 8,232 ==173857== at 0x480B7BB: malloc (vg_replace_malloc.c:380) ==173857== by 0x90143DC: pc_record (in /path/to/python_extension_module.cpython-38-x86_64-linux-gnu.so) ==173857== by 0x9019ABC: walk_children (in /path/to/python_extension_module.cpython-38-x86_64-linux-gnu.so) ==173857== by 0x901974A: __libdw_visit_scopes (in /path/to/python_extension_module.cpython-38-x86_64-linux-gnu.so) ==173857== by 0x9019A69: walk_children (in /path/to/python_extension_module.cpython-38-x86_64-linux-gnu.so) ==173857== by 0x901974A: __libdw_visit_scopes (in /path/to/python_extension_module.cpython-38-x86_64-linux-gnu.so) ==173857== by 0x9014691: dwarf_getscopes (in /path/to/python_extension_module.cpython-38-x86_64-linux-gnu.so) `dwarf_getscopes` ends with: ``` if (result > 0) *scopes = a.scopes; return result; ``` but this is incorrect, since `a.scopes` may be non-NULL even if `result` is <= 0 and is leaked in this case since no reference is retained to it. Seems like this needs to be: ``` if (result > 0) *scopes = a.scopes; else free(a.scopes); return result; ``` -- You are receiving this mail because: You are on the CC list for the bug.