Visitar URL original
bpo-45385: Fix reference leak from descr_check by corona10 · Pull Request #28719 · python/cpython · GitHub
The Wayback Machine - https://web.archive.org/web/20211023112414/https://github.com/python/cpython/pull/28719
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bpo-45385: Fix reference leak from descr_check #28719

Merged
merged 1 commit into from Oct 7, 2021
Merged

Conversation

@corona10
Copy link
Member

@corona10 corona10 commented Oct 4, 2021 •

motivation:

  • GH detects the compiler warnings while executing the CI pipeline.
  • Fix possible reference leak for the method_check_args use-case.

https://bugs.python.org/issue45385

Copy link
Member

@vstinner vstinner left a comment

Your commit title is misleading. What your PR does it is to fix compiler warnings in Objects/descrobject.c. It's unrelated to GitHub Action. It's just that you noticed them thanks for GHA.

@@ -137,7 +137,7 @@ classmethod_get(PyMethodDescrObject *descr, PyObject *obj, PyObject *type)
static PyObject *
method_get(PyMethodDescrObject *descr, PyObject *obj, PyObject *type)
{
PyObject *res;
PyObject *res = NULL;

if (descr_check((PyDescrObject *)descr, obj, &res))
Copy link
Member

@vstinner vstinner Oct 4, 2021

Maybe descr_check() should set res to NULL when it returns 0, whereas having to modify all functions using it.

Copy link
Member

@vstinner vstinner Oct 4, 2021

If you modify descr_check() for that, maybe add a comment to explain that it's only set to NULL to prevent compiler warnings.

Copy link
Member

@vstinner vstinner left a comment

motivation: #28572

Can you please mention the fixed compiler warning in the commit message?

@corona10 corona10 changed the title no-issue: Remove compiler warning from Github Action. no-issue: Fix compiler warnings in Objects/descrobject.c. Oct 4, 2021
@corona10 corona10 changed the title no-issue: Fix compiler warnings in Objects/descrobject.c. no-issue: Fix compiler warnings in Objects/descrobject.c Oct 4, 2021
@vstinner
Copy link
Member

@vstinner vstinner commented Oct 4, 2021

motivation: #28572

I don't see the relationship between your PR and the PR #28572.

@corona10
Copy link
Member Author

@corona10 corona10 commented Oct 4, 2021

I don't see the relationship between your PR and the PR #28572.

I detected the warning from the PR but I will update the content not to mention the PR :)

@corona10 corona10 requested a review from vstinner Oct 4, 2021
@@ -89,6 +89,8 @@ descr_check(PyDescrObject *descr, PyObject *obj, PyObject **pres)
*pres = NULL;
return 1;
}
// Only for preventing compiler warnings.
*pres = NULL;
Copy link
Member Author

@corona10 corona10 Oct 4, 2021

@vstinner
Thanks Victor for review :)
Is this what you intended?

@corona10
Copy link
Member Author

@corona10 corona10 commented Oct 4, 2021

comparison of integer expressions of different signedness: ‘long unsigned int’ and ‘int’ [-Wsign-compare]

Will be fixed at #28716

Copy link
Contributor

@Fidget-Spinner Fidget-Spinner left a comment

LGTM in general. Thank you!

Objects/descrobject.c Outdated Show resolved Hide resolved
Objects/descrobject.c Outdated Show resolved Hide resolved
@corona10 corona10 requested a review from Fidget-Spinner Oct 4, 2021
Objects/descrobject.c Outdated Show resolved Hide resolved
Objects/descrobject.c Outdated Show resolved Hide resolved
Objects/descrobject.c Outdated Show resolved Hide resolved
@corona10 corona10 requested a review from vstinner Oct 4, 2021
@corona10 corona10 changed the title no-issue: Fix compiler warnings in Objects/descrobject.c bpo-45385: Fix compiler warnings in Objects/descrobject.c Oct 6, 2021
@corona10 corona10 changed the title bpo-45385: Fix compiler warnings in Objects/descrobject.c bpo-45385: Fix possible reference leak from descr_check Oct 6, 2021
@corona10 corona10 requested a review from Fidget-Spinner Oct 6, 2021
@corona10
Copy link
Member Author

@corona10 corona10 commented Oct 6, 2021

@vstinner @Fidget-Spinner
PTAL, this PR will fix both compiler warning and possible ref leak :)

return res;
if (obj == NULL) {
Py_INCREF(descr);
return (PyObject *)descr;
Copy link
Member

@vstinner vstinner Oct 6, 2021

Would you mind to use Py_NewRef()?

Copy link
Contributor

@Fidget-Spinner Fidget-Spinner Oct 6, 2021 •

I don't think we can, the bugfix needs to be backported to 3.9. Py_NewRef was added in 3.10. Unless you mean Py_NewRef for 3.11, 3.10 and manual backport for 3.9.

Copy link
Member

@vstinner vstinner Oct 6, 2021

3.10 backport should not prevent to write better code in the main branch. The backport can be different.

Copy link
Member Author

@corona10 corona10 Oct 6, 2021

@vstinner @Fidget-Spinner
I will backport it manually :)

Copy link
Contributor

@Fidget-Spinner Fidget-Spinner left a comment

LGTM. Just needs a news IMO.

return PyWrapper_New((PyObject *)descr, obj);
}

static int
descr_setcheck(PyDescrObject *descr, PyObject *obj, PyObject *value,
Copy link
Contributor

@Fidget-Spinner Fidget-Spinner Oct 6, 2021

Wow, why did this (and the code below) change too? I don't think this was buggy, though the new code improves readability/makes it easier to understand.

I'm guessing for consistency reasons?

Copy link
Member

@vstinner vstinner Oct 6, 2021

I asked @corona10 to mention compiler warnings in the commit message. I cannot see compiler warnings in https://bugs.python.org/issue45385, in the PR description, or in the commit message.

Copy link
Member Author

@corona10 corona10 Oct 6, 2021

I'm guessing for consistency reasons?

Yes and it improve the readability :)

if (descr_check((PyDescrObject *)descr, obj, &res))
return res;
if (obj == NULL) {
return Py_NewRef((PyObject *)descr);
Copy link
Member

@vstinner vstinner Oct 6, 2021

There is no need to cast the Py_NewRef() argument to PyObject*.

Copy link
Member Author

@corona10 corona10 Oct 6, 2021

Updated!

@corona10 corona10 requested a review from vstinner Oct 6, 2021
Copy link
Member

@vstinner vstinner left a comment

LGTM. But please mention the fixed compiler warnings in the commit message and/or in the bpo.

"Fix possible reference leak". Either there is a leak or not leak. I suggest to remove "possible".

@corona10 corona10 changed the title bpo-45385: Fix possible reference leak from descr_check bpo-45385: Fix reference leak from descr_check Oct 6, 2021
@bedevere-bot
Copy link

@bedevere-bot bedevere-bot commented Oct 6, 2021

🤖 New build scheduled with the buildbot fleet by @Fidget-Spinner for commit 336434c 🤖

If you want to schedule another build, you need to add the "🔨 test-with-buildbots" label again.

@corona10 corona10 merged commit e6ff4eb into python:main Oct 7, 2021
63 checks passed
@miss-islington
Copy link
Contributor

@miss-islington miss-islington commented Oct 7, 2021

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

@bedevere-bot
Copy link

@bedevere-bot bedevere-bot commented Oct 7, 2021

@corona10: Please replace # with GH- in the commit message next time. Thanks!

@bedevere-bot
Copy link

@bedevere-bot bedevere-bot commented Oct 7, 2021

GH-28779 is a backport of this pull request to the 3.10 branch.

miss-islington added a commit to miss-islington/cpython that referenced this issue Oct 7, 2021
(cherry picked from commit e6ff4eb)

Co-authored-by: Dong-hee Na <donghee.na@python.org>
@corona10 corona10 deleted the nit branch Oct 7, 2021
corona10 added a commit to corona10/cpython that referenced this issue Oct 7, 2021
(cherry picked from commit e6ff4eb)

Co-authored-by: Dong-hee Na <donghee.na@python.org>
@bedevere-bot
Copy link

@bedevere-bot bedevere-bot commented Oct 7, 2021

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

Hi! The buildbot x86-64 macOS 3.x has failed when building commit e6ff4eb.

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/all/#builders/366/builds/1003) and take a look at the build logs.
  4. Check if the failure is related to this commit (e6ff4eb) 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/all/#builders/366/builds/1003

Failed tests:

  • test_importlib

Failed subtests:

  • test_multiprocessing_pool_circular_import - test.test_importlib.test_threaded_import.ThreadedImportTests

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

== Tests result: FAILURE then FAILURE ==

408 tests OK.

10 slowest tests:

  • test_concurrent_futures: 4 min 29 sec
  • test_multiprocessing_spawn: 4 min
  • test_unparse: 3 min 26 sec
  • test_tokenize: 3 min 17 sec
  • test_lib2to3: 2 min 29 sec
  • test_multiprocessing_forkserver: 2 min 17 sec
  • test_unicodedata: 2 min 9 sec
  • test_asyncio: 1 min 57 sec
  • test_capi: 1 min 41 sec
  • test_pickle: 1 min 15 sec

1 test failed:
test_importlib

18 tests skipped:
test_devpoll test_epoll test_gdb test_ioctl test_msilib
test_multiprocessing_fork test_ossaudiodev test_smtpnet test_spwd
test_ssl test_startfile test_tix test_tk test_ttk_guionly
test_winconsoleio test_winreg test_winsound test_zipfile64

1 re-run test:
test_importlib

Total duration: 29 min 19 sec

Click to see traceback logs
Traceback (most recent call last):
  File "/Users/buildbot/buildarea/3.x.billenstein-macos/build/Lib/multiprocessing/resource_tracker.py", line 209, in main
    cache[rtype].remove(name)
    ^^^^^^^^^^^^^^^^^^^^^^^^^
KeyError: '/psm_660b9f0f'


Traceback (most recent call last):
  File "/Users/buildbot/buildarea/3.x.billenstein-macos/build/Lib/test/test_importlib/test_threaded_import.py", line 258, in test_multiprocessing_pool_circular_import
    script_helper.assert_python_ok(fn)
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/buildbot/buildarea/3.x.billenstein-macos/build/Lib/test/support/script_helper.py", line 160, in assert_python_ok
    return _assert_python(True, *args, **env_vars)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/buildbot/buildarea/3.x.billenstein-macos/build/Lib/test/support/script_helper.py", line 145, in _assert_python
    res.fail(cmd_line)
    ^^^^^^^^^^^^^^^^^^
  File "/Users/buildbot/buildarea/3.x.billenstein-macos/build/Lib/test/support/script_helper.py", line 72, in fail
    raise AssertionError("Process return code is %d\n"
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: Process return code is 1
command line: ['/Users/buildbot/buildarea/3.x.billenstein-macos/build/python.exe', '-X', 'faulthandler', '-I', '/Users/buildbot/buildarea/3.x.billenstein-macos/build/Lib/test/test_importlib/partial/pool_in_threads.py']


Traceback (most recent call last):
  File "/Users/buildbot/buildarea/3.x.billenstein-macos/build/Lib/multiprocessing/resource_tracker.py", line 209, in main
    cache[rtype].remove(name)
    ^^^^^^^^^^^^^^^^^^^^^^^^^
KeyError: '/psm_660c8d6e'

corona10 added a commit to corona10/cpython that referenced this issue Oct 7, 2021
(cherry picked from commit e6ff4eb)

Co-authored-by: Dong-hee Na <donghee.na@python.org>
corona10 added a commit that referenced this issue Oct 7, 2021
…8780)

(cherry picked from commit e6ff4eb)

Co-authored-by: Dong-hee Na <donghee.na@python.org>
methane added a commit to methane/cpython that referenced this issue Oct 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
6 participants