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

BUGFIX: Fixed A File Descriptor Leak Related Bug #9

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

fazledyn
Copy link

Overview

This PR fixes a file descriptor leak related bug in heat.py file. The calling of mkstemp() returns a random temp file name and a file descriptor. It becomes the responsibility of the user to close that file descriptor. Having too much of open file descriptors leads to an OSError [Errno 24].

PoC

from tempfile import mkstemp
import os

def heat():
        _, tmp_file = mkstemp()
        with open(tmp_file, "w") as f:
                f.write("foo")
        # do something
        os.remove(tmp_file)

if __name__ == "__main__":
        for i in range(100_000):
                print(i+1)
                heat()

Running the above program gives the output:

...
1019
1020
1021
Traceback (most recent call last):
  File "/mnt/f/GitHub/test_pyheat.py", line 17, in <module>
  File "/mnt/f/GitHub/test_pyheat.py", line 7, in heat
OSError: [Errno 24] Too many open files: '/tmp/tmp3h57izmy'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants