]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commit
gdb/python: fix memory leak of gdb.Color objects
authorAndrew Burgess <aburgess@redhat.com>
Fri, 18 Apr 2025 21:42:17 +0000 (22:42 +0100)
committerAndrew Burgess <aburgess@redhat.com>
Tue, 22 Apr 2025 16:21:59 +0000 (17:21 +0100)
commit5d4187339f9f2f338d540adbdfd174aa9f1e92ab
tree1a0af6ebcf2de425cbea28755e3cfac5a4bb58a0
parent93c145c2aaf3b85b7c3b7abee029da5438d6732f
gdb/python: fix memory leak of gdb.Color objects

I noticed that this commit:

  commit 6447969d0ac774b6dec0f95a0d3d27c27d158690
  Date:   Sat Oct 5 22:27:44 2024 +0300

      Add an option with a color type.

has an unnecessary `Py_INCREF (self);` in gdb.Color.__init__.  This
means that the reference count on all gdb.Color objects (that pass
through __init__) will be +1 from where they should normally be, and
this will stop the gdb.Color objects from being deallocated.

Fix by removing the Py_INCREF call.

Add a test which exposes the memory leak.

Approved-By: Tom Tromey <tom@tromey.com>
gdb/python/py-color.c
gdb/testsuite/gdb.python/py-color-leak.exp [new file with mode: 0644]
gdb/testsuite/gdb.python/py-color-leak.py [new file with mode: 0644]