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

Fixed an issue where __init__.check_dt_compatible_value opened a file… #88

Conversation

fpdotmonkey
Copy link
Contributor

… but did not close it and thus caused a memory leak and a ResourceWarning.

I also wrote this test program to verify that my change worked. If it would be helpful, I can add it to the repo in an additional commit.

#
# Run this test with `python3 -m unittest` in 
# `Adafruit_Python_PlatformDetect/adafruit_platformdetect`
#
import unittest
import warnings

from __init__ import Detector


class TestDetector(unittest.TestCase):

    def test_check_dt_compatible_value_closes_file(self):
        detector = Detector()
        with warnings.catch_warnings(record=True) as warning:
            warnings.simplefilter("default", category=ResourceWarning)
            detector.check_dt_compatible_value("test")
            self.assertEquals(len(warning), 0,
                              "The file `/proc/device-tree/compatible` "
                              "is not\nbeing closed and Detector is "
                              "leaking memory.")

… but did not close it and thus caused a memory leak and a ResourceWarning.
Copy link
Contributor

@makermelissa makermelissa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for finding and fixing this.

@makermelissa makermelissa merged commit 5cdf8af into adafruit:master Jul 2, 2020
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