public inbox for elfutils@sourceware.org
 help / color / mirror / Atom feed
* [Bug libdw/29434] New: Memory leak in `dwarf_getscopes`
@ 2022-08-01 16:07 godlygeek at gmail dot com
  2022-08-04 14:30 ` [Bug libdw/29434] " mark at klomp dot org
                   ` (18 more replies)
  0 siblings, 19 replies; 20+ messages in thread
From: godlygeek at gmail dot com @ 2022-08-01 16:07 UTC (permalink / raw)
  To: elfutils-devel

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.

^ permalink raw reply	[flat|nested] 20+ messages in thread

end of thread, other threads:[~2023-02-28 11:38 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-01 16:07 [Bug libdw/29434] New: Memory leak in `dwarf_getscopes` godlygeek at gmail dot com
2022-08-04 14:30 ` [Bug libdw/29434] " mark at klomp dot org
2022-08-04 14:43 ` pablogsal at gmail dot com
2022-08-04 15:13 ` mark at klomp dot org
2022-08-04 15:52 ` pablogsal at gmail dot com
2022-08-04 15:57 ` mark at klomp dot org
2022-08-04 16:05 ` pablogsal at gmail dot com
2022-08-04 16:07 ` pablogsal at gmail dot com
2022-08-04 16:11 ` pablogsal at gmail dot com
2022-08-29 15:28 ` mark at klomp dot org
2022-10-27 20:37 ` mark at klomp dot org
2022-11-03 16:21 ` pablogsal at gmail dot com
2022-11-03 16:22 ` pablogsal at gmail dot com
2022-11-03 16:44 ` pablogsal at gmail dot com
2022-11-03 16:45 ` pablogsal at gmail dot com
2022-11-03 16:58 ` pablogsal at gmail dot com
2022-12-21 13:06 ` mark at klomp dot org
2023-02-22 17:18 ` mark at klomp dot org
2023-02-22 22:41 ` mark at klomp dot org
2023-02-28 11:38 ` mark at klomp dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).