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

Fix a resource leak: close fp before return (found by cppcheck) #3061

Merged
merged 2 commits into from
Apr 2, 2018

Conversation

kathryndavies
Copy link
Contributor

Minor fix for resource leak found by cppcheck.

@homm
Copy link
Member

homm commented Mar 31, 2018

Please add the following test in Tests/test_image.py right after the test_internals:

    def test_internals(self):
        im = Image.new("L", (100, 100))
        im.readonly = 1
        im._copy()
        self.assertFalse(im.readonly)

        im.readonly = 1
        im.paste(0, (0, 0, 100, 100))
        self.assertFalse(im.readonly)

    def test_dump(self):
        im = Image.new("L", (10, 10))
        im._dump(self.tempfile("temp_L.ppm"))

        im = Image.new("RGB", (10, 10))
        im._dump(self.tempfile("temp_RGB.ppm"))

        im = Image.new("HSV", (10, 10))
        self.assertRaises(ValueError, im._dump, self.tempfile("temp_HSV.ppm"))

@@ -71,6 +71,7 @@ ImagingSavePPM(Imaging im, const char* outfile)
fprintf(fp, "P6\n%d %d\n255\n", im->xsize, im->ysize);
} else {
(void) ImagingError_ModeError();
fclose(fp);
Copy link
Member

Choose a reason for hiding this comment

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

Please, change line order: place fclose before ImagingError_ModeError.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the code review - I've made the changes.

@wiredfool wiredfool merged commit 8cc9713 into python-pillow:master Apr 2, 2018
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.

None yet

3 participants