simpleMDMpy icon indicating copy to clipboard operation
simpleMDMpy copied to clipboard

Files are opened, but not closed explicitly

Open disconnect3d opened this issue 4 years ago • 1 comments

There are 5 instances when a file is opened to be read, but it is not closed explicitly. Because of it, there is a risk the file won't be closed and so a file descriptor limit can be exceeded (causing a program crash), depending on the given Python interpreter implementation.

Those instances can be found e.g. with ripgrep:

$ rg open
Apps.py
32:            files['binary'] = open(binary, 'rb')
43:            files['binary'] = open(binary, 'rb')

CustomConfigurationProfiles.py
23:        files = {'mobileconfig': open(mobileconfig, 'rb')}
39:            files['mobileconfig'] = open(mobileconfig, 'rb')

PushCertificate.py
23:        files = {'file': open(file, 'rb')}

Those cases should be changed to use the with statement so they explicitly .close() the file when the function returns or when an exception is thrown.

disconnect3d avatar Jul 26 '21 16:07 disconnect3d

Re-opening, see context in #34 for what needs to be done still.

rickheil avatar Dec 07 '23 21:12 rickheil