Skip to content

bpo-40645: Fix reference leak in the _hashopenssl extension - #26072

Merged
miss-islington merged 1 commit into
python:mainfrom
encukou:hashlib-refleak
May 12, 2021
Merged

miss-islington merged 1 commit into
python:mainfrom
encukou:hashlib-refleak

Conversation

@encukou

@encukou encukou commented May 12, 2021 •

Copy link
Copy Markdown
Member

The PyModule_AddObjectRef function doesn't steal a reference, so an extra Py_DECREF is needed.

https://bugs.python.org/issue40645

Automerge-Triggered-By: GH:tiran

The PyModule_AddObjectRef function doesn't steal a reference,
so an extra Py_DECREF is needed.
@tiran

tiran commented May 12, 2021

Copy link
Copy Markdown
Member

Thank you!

@erlend-aasland

erlend-aasland commented May 12, 2021 •

Copy link
Copy Markdown
Contributor

There's also three leaks in the preceding for-loop:name_obj and func => fixed in 26079

Comment thread Modules/_hashopenssl.c
Comment on lines 2109 to +2112
if (PyModule_AddObjectRef(module, "_constructors", proxy) < 0) {
return -1;
}
Py_DECREF(proxy);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Decref in case PyModule_AddObjectRef fails, no?

Suggested change
if (PyModule_AddObjectRef(module, "_constructors", proxy) < 0) {
return -1;
}
Py_DECREF(proxy);
int rc = PyModule_AddObjectRef(module, "_constructors", proxy);
Py_DECREF(proxy);
if (rc < 0) {
return -1;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

FYI, fixed in #26079

@miss-islington

Copy link
Copy Markdown
Contributor

@encukou: Status check is done, and it's a success ✅ .

@miss-islington
miss-islington merged commit 3611db5 into python:main May 12, 2021
@miss-islington

Copy link
Copy Markdown
Contributor

Thanks @encukou for the PR 🌮🎉.. I'm working now to backport this PR to: 3.10.
🐍🍒⛏🤖

@miss-islington

Copy link
Copy Markdown
Contributor

Sorry @encukou, I had trouble checking out the 3.10 backport branch.
Please backport using cherry_picker on command line.
cherry_picker 3611db53f5b854cb6d01ee5ebb5e11c87bcc2df5 3.10

@Mariatta

Mariatta commented Jun 2, 2021

Copy link
Copy Markdown
Member

Does this still need backport to 3.10?

@erlend-aasland

Copy link
Copy Markdown
Contributor

Does this still need backport to 3.10?

I believe so, yes.

cc @pablogsal.

@pablogsal

Copy link
Copy Markdown
Member

Does this still need backport to 3.10?

I believe so, yes.

cc @pablogsal.

This indeed need to be backported

@erlend-aasland

Copy link
Copy Markdown
Contributor

I can create a backport of this together with a backport of #26079, @pablogsal. Let me know if that's ok with you, @encukou.

@encukou

encukou commented Jun 4, 2021

Copy link
Copy Markdown
Member Author

It is. Thank you!

@encukou
encukou deleted the hashlib-refleak branch June 4, 2021 08:00
@erlend-aasland

Copy link
Copy Markdown
Contributor

Oh, I already did this in #26082 :) Backport is done; no further actions needed.

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

8 participants