Skip to content

A possible resource leak in Python 3.11.0 #98872

Closed
@SQLPATCH

Description

@SQLPATCH

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    type-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions