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

A possible resource leak in Python 3.11.0 #98872

Closed
SQLPATCH opened this issue Oct 30, 2022 · 2 comments
Closed

A possible resource leak in Python 3.11.0 #98872

SQLPATCH opened this issue Oct 30, 2022 · 2 comments
Labels
type-bug An unexpected behavior, bug, or error

Comments

@SQLPATCH
Copy link
Contributor

SQLPATCH commented Oct 30, 2022

Bug report

Hi, I'm currently using Infer, a static analysis tool, to analyze the native code of CPython.
I found a possible resource leak vulnerability:
Resource of type _IO_FILE acquired by call to fopen() at line 184 is not released after line 196.

Programs/_freeze_module.c:196:

  195.     if (ferror(outfile)) {
  196.         fprintf(stderr, "error when writing to '%s'\n", outpath);
                       ^
  197.         return -1;
  198.     }

I think that resource should be released before exiting, a PR maybe like:

    if (ferror(outfile)) {
        fprintf(stderr, "error when writing to '%s'\n", outpath);
        fclose(outfile);
        return -1;
     }

Python is my favorite programming language. I hope this discovery can be helpful to you!

My environment

  • CPython versions tested on: 3.11.0
  • Operating system and architecture: Ubuntu 22.04
@SQLPATCH SQLPATCH added the type-bug An unexpected behavior, bug, or error label Oct 30, 2022
@corona10
Copy link
Member

corona10 commented Nov 2, 2022

@SQLPATCH
Would you like to submit the patch?

SQLPATCH added a commit to SQLPATCH/cpython that referenced this issue Nov 3, 2022
miss-islington pushed a commit that referenced this issue Nov 24, 2022
Issue: #98872

Automerge-Triggered-By: GH:kumaraditya303
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Nov 24, 2022
…GH-99047)

Issue: pythonGH-98872
(cherry picked from commit 4e5f2db)

Co-authored-by: SQLPATCH <[email protected]>
Automerge-Triggered-By: GH:kumaraditya303
miss-islington added a commit that referenced this issue Nov 24, 2022
Issue: GH-98872
(cherry picked from commit 4e5f2db)

Co-authored-by: SQLPATCH <[email protected]>
Automerge-Triggered-By: GH:kumaraditya303
@kumaraditya303
Copy link
Contributor

kumaraditya303 commented Nov 24, 2022

Thanks for the bug report and PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

3 participants