diff options
author | Andrew Burgess <aburgess@redhat.com> | 2024-11-19 10:37:49 +0000 |
---|---|---|
committer | Andrew Burgess <aburgess@redhat.com> | 2024-11-20 09:33:17 +0000 |
commit | 661611b9d71d9358305332d28a8b9d7bb47a4363 (patch) | |
tree | 692ee91c06716a98abf5ec118611807d0805d21e /gdb/testsuite/gdb.base/huge.c | |
parent | 00ef37e860d505f41a621708c62f3e9363868ee1 (diff) | |
download | gdb-master.zip gdb-master.tar.gz gdb-master.tar.bz2 |
While reviewing another patch which uses PyList_Append I took a look
at our other uses of PyList_Append in GDB. I spotted something odd
about the use in bplocpy_get_thread_groups.
We do:
gdbpy_ref<> num = gdb_py_object_from_ulongest (inf->num);
At which point `num` will own a reference to the `int` object. But
when we add the object to the result list we do:
if (PyList_Append (list.get (), num.release ()) != 0)
return nullptr;
By calling `release` we pass ownership of the reference to
PyList_Append, however, PyList_Append acquires its own reference, it
doesn't take ownership of an existing reference.
The consequence of this is that we leak the reference held in `num`.
This mostly isn't a problem though. For small (< 257) integers Python
keeps a single instance of each and just hands out new references. By
leaking the references, these small integers will not be cleaned up as
the Python interpreter shuts down, but that is only done when GDB
exits, so hardly a disaster. As we're dealing with GDB's internal
inferior number here, unless the user has 257+ inferiors, we'll not
actually be leaking memory.
Still, lets do things right. Switch to using `num.get ()`. Now when
`num` goes out of scope it will decrement the reference count as
needed.
Approved-By: Tom Tromey <tom@tromey.com>
Diffstat (limited to 'gdb/testsuite/gdb.base/huge.c')
0 files changed, 0 insertions, 0 deletions