X Tutup
Skip to content

gh-145376: Fix various refleaks Objects/#145609

Merged
vstinner merged 10 commits intopython:mainfrom
eendebakpt:refleaks_misc
Mar 9, 2026
Merged

gh-145376: Fix various refleaks Objects/#145609
vstinner merged 10 commits intopython:mainfrom
eendebakpt:refleaks_misc

Conversation

@eendebakpt
Copy link
Contributor

@eendebakpt eendebakpt commented Mar 6, 2026

attr_old = getattrs(self->win);
if (curses_wattrset(self, attr, "addstr") < 0) {
curses_release_wstr(strtype, wstr);
Py_DECREF(bytesobj);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Be careful here. PyCurses_ConvertToString has a weird return type so you might not necessarily have bytesobj set to something (it might be in wstr instead).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you move this line after the if instead so we don't have to worry about cleaning up the ref?

Copy link
Member

@vstinner vstinner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I check all changes and they LGTM.

@vstinner vstinner merged commit 8060aa5 into python:main Mar 9, 2026
54 checks passed
@vstinner
Copy link
Member

vstinner commented Mar 9, 2026

Merged. Thans for the fix.

@bedevere-bot
Copy link

⚠️⚠️⚠️ Buildbot failure ⚠️⚠️⚠️

Hi! The buildbot AMD64 FreeBSD 3.x (tier-3) has failed when building commit 8060aa5.

What do you need to do:

  1. Don't panic.
  2. Check the buildbot page in the devguide if you don't know what the buildbots are or how they work.
  3. Go to the page of the buildbot that failed (https://buildbot.python.org/#/builders/1223/builds/8317) and take a look at the build logs.
  4. Check if the failure is related to this commit (8060aa5) or if it is a false positive.
  5. If the failure is related to this commit, please, reflect that on the issue and make a new Pull Request with a fix.

You can take a look at the buildbot page here:

https://buildbot.python.org/#/builders/1223/builds/8317

Summary of the results of the build (if available):

Click to see traceback logs
remote: Enumerating objects: 21, done.        
remote: Counting objects:   4% (1/21)        
remote: Counting objects:   9% (2/21)        
remote: Counting objects:  14% (3/21)        
remote: Counting objects:  19% (4/21)        
remote: Counting objects:  23% (5/21)        
remote: Counting objects:  28% (6/21)        
remote: Counting objects:  33% (7/21)        
remote: Counting objects:  38% (8/21)        
remote: Counting objects:  42% (9/21)        
remote: Counting objects:  47% (10/21)        
remote: Counting objects:  52% (11/21)        
remote: Counting objects:  57% (12/21)        
remote: Counting objects:  61% (13/21)        
remote: Counting objects:  66% (14/21)        
remote: Counting objects:  71% (15/21)        
remote: Counting objects:  76% (16/21)        
remote: Counting objects:  80% (17/21)        
remote: Counting objects:  85% (18/21)        
remote: Counting objects:  90% (19/21)        
remote: Counting objects:  95% (20/21)        
remote: Counting objects: 100% (21/21)        
remote: Counting objects: 100% (21/21), done.        
remote: Compressing objects:  10% (1/10)        
remote: Compressing objects:  20% (2/10)        
remote: Compressing objects:  30% (3/10)        
remote: Compressing objects:  40% (4/10)        
remote: Compressing objects:  50% (5/10)        
remote: Compressing objects:  60% (6/10)        
remote: Compressing objects:  70% (7/10)        
remote: Compressing objects:  80% (8/10)        
remote: Compressing objects:  90% (9/10)        
remote: Compressing objects: 100% (10/10)        
remote: Compressing objects: 100% (10/10), done.        
remote: Total 11 (delta 10), reused 1 (delta 1), pack-reused 0 (from 0)        
From https://github.com/python/cpython
 * branch                    main       -> FETCH_HEAD
Note: switching to '8060aa5d7dd02c22a987e23cf5dbb7049b50b042'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by switching back to a branch.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -c with the switch command. Example:

  git switch -c <new-branch-name>

Or undo this operation with:

  git switch -

Turn off this advice by setting config variable advice.detachedHead to false

HEAD is now at 8060aa5d7dd gh-145376: Fix various refleaks in Objects/ (#145609)
Switched to and reset branch 'main'

1 error

@bedevere-bot
Copy link

⚠️⚠️⚠️ Buildbot failure ⚠️⚠️⚠️

Hi! The buildbot ARM64 MacOS M1 NoGIL 3.x (tier-2) has failed when building commit 8060aa5.

What do you need to do:

  1. Don't panic.
  2. Check the buildbot page in the devguide if you don't know what the buildbots are or how they work.
  3. Go to the page of the buildbot that failed (https://buildbot.python.org/#/builders/1270/builds/6984) and take a look at the build logs.
  4. Check if the failure is related to this commit (8060aa5) or if it is a false positive.
  5. If the failure is related to this commit, please, reflect that on the issue and make a new Pull Request with a fix.

You can take a look at the buildbot page here:

https://buildbot.python.org/#/builders/1270/builds/6984

Summary of the results of the build (if available):

Click to see traceback logs
remote: Enumerating objects: 21, done.        
remote: Counting objects:   4% (1/21)        
remote: Counting objects:   9% (2/21)        
remote: Counting objects:  14% (3/21)        
remote: Counting objects:  19% (4/21)        
remote: Counting objects:  23% (5/21)        
remote: Counting objects:  28% (6/21)        
remote: Counting objects:  33% (7/21)        
remote: Counting objects:  38% (8/21)        
remote: Counting objects:  42% (9/21)        
remote: Counting objects:  47% (10/21)        
remote: Counting objects:  52% (11/21)        
remote: Counting objects:  57% (12/21)        
remote: Counting objects:  61% (13/21)        
remote: Counting objects:  66% (14/21)        
remote: Counting objects:  71% (15/21)        
remote: Counting objects:  76% (16/21)        
remote: Counting objects:  80% (17/21)        
remote: Counting objects:  85% (18/21)        
remote: Counting objects:  90% (19/21)        
remote: Counting objects:  95% (20/21)        
remote: Counting objects: 100% (21/21)        
remote: Counting objects: 100% (21/21), done.        
remote: Compressing objects:  10% (1/10)        
remote: Compressing objects:  20% (2/10)        
remote: Compressing objects:  30% (3/10)        
remote: Compressing objects:  40% (4/10)        
remote: Compressing objects:  50% (5/10)        
remote: Compressing objects:  60% (6/10)        
remote: Compressing objects:  70% (7/10)        
remote: Compressing objects:  80% (8/10)        
remote: Compressing objects:  90% (9/10)        
remote: Compressing objects: 100% (10/10)        
remote: Compressing objects: 100% (10/10), done.        
remote: Total 11 (delta 10), reused 1 (delta 1), pack-reused 0 (from 0)        
From https://github.com/python/cpython
 * branch                    main       -> FETCH_HEAD
Note: switching to '8060aa5d7dd02c22a987e23cf5dbb7049b50b042'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by switching back to a branch.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -c with the switch command. Example:

  git switch -c <new-branch-name>

Or undo this operation with:

  git switch -

Turn off this advice by setting config variable advice.detachedHead to false

HEAD is now at 8060aa5d7dd gh-145376: Fix various refleaks in Objects/ (#145609)
Switched to and reset branch 'main'

configure: WARNING: pkg-config is missing. Some dependencies may not be detected correctly.

./Modules/_cursesmodule.c:1135:16: error: use of undeclared identifier 'wstr'; did you mean 'str'?
 1135 |         assert(wstr == NULL);
      |                ^~~~
      |                str
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/assert.h:75:25: note: expanded from macro 'assert'
   75 |     (__builtin_expect(!(e), 0) ? __assert_rtn(__func__, __ASSERT_FILE_NAME, __LINE__, #e) : (void)0)
      |                         ^
./Modules/_cursesmodule.c:1089:52: note: 'str' declared here
 1089 |                            int y, int x, PyObject *str, int group_right_1,
      |                                                    ^
1 error generated.
make: *** [Modules/_cursesmodule.o] Error 1
make: *** Waiting for unfinished jobs....

find: build: No such file or directory
find: build: No such file or directory
find: build: No such file or directory
find: build: No such file or directory
make: [clean-retain-profile] Error 1 (ignored)

@vstinner
Copy link
Member

vstinner commented Mar 9, 2026

Oh, macOS and FreeBSD fail to build _cursesmodule.c with this change!

./Modules/_cursesmodule.c:1135:16: error: use of undeclared identifier 'wstr'; did you mean 'str'?

I wrote #145669 to fix it.

@bedevere-bot
Copy link

⚠️⚠️⚠️ Buildbot failure ⚠️⚠️⚠️

Hi! The buildbot x86-64 MacOS Intel NoGIL 3.x (tier-2) has failed when building commit 8060aa5.

What do you need to do:

  1. Don't panic.
  2. Check the buildbot page in the devguide if you don't know what the buildbots are or how they work.
  3. Go to the page of the buildbot that failed (https://buildbot.python.org/#/builders/1258/builds/7049) and take a look at the build logs.
  4. Check if the failure is related to this commit (8060aa5) or if it is a false positive.
  5. If the failure is related to this commit, please, reflect that on the issue and make a new Pull Request with a fix.

You can take a look at the buildbot page here:

https://buildbot.python.org/#/builders/1258/builds/7049

Summary of the results of the build (if available):

Click to see traceback logs
remote: Enumerating objects: 72, done.        
remote: Counting objects:   1% (1/72)        
remote: Counting objects:   2% (2/72)        
remote: Counting objects:   4% (3/72)        
remote: Counting objects:   5% (4/72)        
remote: Counting objects:   6% (5/72)        
remote: Counting objects:   8% (6/72)        
remote: Counting objects:   9% (7/72)        
remote: Counting objects:  11% (8/72)        
remote: Counting objects:  12% (9/72)        
remote: Counting objects:  13% (10/72)        
remote: Counting objects:  15% (11/72)        
remote: Counting objects:  16% (12/72)        
remote: Counting objects:  18% (13/72)        
remote: Counting objects:  19% (14/72)        
remote: Counting objects:  20% (15/72)        
remote: Counting objects:  22% (16/72)        
remote: Counting objects:  23% (17/72)        
remote: Counting objects:  25% (18/72)        
remote: Counting objects:  26% (19/72)        
remote: Counting objects:  27% (20/72)        
remote: Counting objects:  29% (21/72)        
remote: Counting objects:  30% (22/72)        
remote: Counting objects:  31% (23/72)        
remote: Counting objects:  33% (24/72)        
remote: Counting objects:  34% (25/72)        
remote: Counting objects:  36% (26/72)        
remote: Counting objects:  37% (27/72)        
remote: Counting objects:  38% (28/72)        
remote: Counting objects:  40% (29/72)        
remote: Counting objects:  41% (30/72)        
remote: Counting objects:  43% (31/72)        
remote: Counting objects:  44% (32/72)        
remote: Counting objects:  45% (33/72)        
remote: Counting objects:  47% (34/72)        
remote: Counting objects:  48% (35/72)        
remote: Counting objects:  50% (36/72)        
remote: Counting objects:  51% (37/72)        
remote: Counting objects:  52% (38/72)        
remote: Counting objects:  54% (39/72)        
remote: Counting objects:  55% (40/72)        
remote: Counting objects:  56% (41/72)        
remote: Counting objects:  58% (42/72)        
remote: Counting objects:  59% (43/72)        
remote: Counting objects:  61% (44/72)        
remote: Counting objects:  62% (45/72)        
remote: Counting objects:  63% (46/72)        
remote: Counting objects:  65% (47/72)        
remote: Counting objects:  66% (48/72)        
remote: Counting objects:  68% (49/72)        
remote: Counting objects:  69% (50/72)        
remote: Counting objects:  70% (51/72)        
remote: Counting objects:  72% (52/72)        
remote: Counting objects:  73% (53/72)        
remote: Counting objects:  75% (54/72)        
remote: Counting objects:  76% (55/72)        
remote: Counting objects:  77% (56/72)        
remote: Counting objects:  79% (57/72)        
remote: Counting objects:  80% (58/72)        
remote: Counting objects:  81% (59/72)        
remote: Counting objects:  83% (60/72)        
remote: Counting objects:  84% (61/72)        
remote: Counting objects:  86% (62/72)        
remote: Counting objects:  87% (63/72)        
remote: Counting objects:  88% (64/72)        
remote: Counting objects:  90% (65/72)        
remote: Counting objects:  91% (66/72)        
remote: Counting objects:  93% (67/72)        
remote: Counting objects:  94% (68/72)        
remote: Counting objects:  95% (69/72)        
remote: Counting objects:  97% (70/72)        
remote: Counting objects:  98% (71/72)        
remote: Counting objects: 100% (72/72)        
remote: Counting objects: 100% (72/72), done.        
remote: Compressing objects:   2% (1/37)        
remote: Compressing objects:   5% (2/37)        
remote: Compressing objects:   8% (3/37)        
remote: Compressing objects:  10% (4/37)        
remote: Compressing objects:  13% (5/37)        
remote: Compressing objects:  16% (6/37)        
remote: Compressing objects:  18% (7/37)        
remote: Compressing objects:  21% (8/37)        
remote: Compressing objects:  24% (9/37)        
remote: Compressing objects:  27% (10/37)        
remote: Compressing objects:  29% (11/37)        
remote: Compressing objects:  32% (12/37)        
remote: Compressing objects:  35% (13/37)        
remote: Compressing objects:  37% (14/37)        
remote: Compressing objects:  40% (15/37)        
remote: Compressing objects:  43% (16/37)        
remote: Compressing objects:  45% (17/37)        
remote: Compressing objects:  48% (18/37)        
remote: Compressing objects:  51% (19/37)        
remote: Compressing objects:  54% (20/37)        
remote: Compressing objects:  56% (21/37)        
remote: Compressing objects:  59% (22/37)        
remote: Compressing objects:  62% (23/37)        
remote: Compressing objects:  64% (24/37)        
remote: Compressing objects:  67% (25/37)        
remote: Compressing objects:  70% (26/37)        
remote: Compressing objects:  72% (27/37)        
remote: Compressing objects:  75% (28/37)        
remote: Compressing objects:  78% (29/37)        
remote: Compressing objects:  81% (30/37)        
remote: Compressing objects:  83% (31/37)        
remote: Compressing objects:  86% (32/37)        
remote: Compressing objects:  89% (33/37)        
remote: Compressing objects:  91% (34/37)        
remote: Compressing objects:  94% (35/37)        
remote: Compressing objects:  97% (36/37)        
remote: Compressing objects: 100% (37/37)        
remote: Compressing objects: 100% (37/37), done.        
remote: Total 41 (delta 35), reused 6 (delta 4), pack-reused 0 (from 0)        
From https://github.com/python/cpython
 * branch                    main       -> FETCH_HEAD
Note: switching to '8060aa5d7dd02c22a987e23cf5dbb7049b50b042'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by switching back to a branch.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -c with the switch command. Example:

  git switch -c <new-branch-name>

Or undo this operation with:

  git switch -

Turn off this advice by setting config variable advice.detachedHead to false

HEAD is now at 8060aa5d7dd gh-145376: Fix various refleaks in Objects/ (#145609)
Switched to and reset branch 'main'

configure: WARNING: pkg-config is missing. Some dependencies may not be detected correctly.

./Modules/_cursesmodule.c:1135:16: error: use of undeclared identifier 'wstr'; did you mean 'str'?
        assert(wstr == NULL);
               ^~~~
               str
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/assert.h:99:25: note: expanded from macro 'assert'
    (__builtin_expect(!(e), 0) ? __assert_rtn(__func__, __ASSERT_FILE_NAME, __LINE__, #e) : (void)0)
                        ^
./Modules/_cursesmodule.c:1089:52: note: 'str' declared here
                           int y, int x, PyObject *str, int group_right_1,
                                                   ^
1 error generated.
make: *** [Modules/_cursesmodule.o] Error 1
make: *** Waiting for unfinished jobs....

find: build: No such file or directory
find: build: No such file or directory
find: build: No such file or directory
find: build: No such file or directory
make: [clean-retain-profile] Error 1 (ignored)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants

X Tutup