Skip to content

Commit

Permalink
Merge pull request #3061 from kathryndavies/master
Browse files Browse the repository at this point in the history
Fix a resource leak: close fp before return
  • Loading branch information
wiredfool committed Apr 2, 2018
2 parents f474646 + 8f6be2e commit 8cc9713
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
12 changes: 9 additions & 3 deletions Tests/test_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ def test_unknown_extension(self):
self.assertRaises(ValueError, im.save, temp_file)

def test_internals(self):

im = Image.new("L", (100, 100))
im.readonly = 1
im._copy()
Expand All @@ -122,8 +121,15 @@ def test_internals(self):
im.paste(0, (0, 0, 100, 100))
self.assertFalse(im.readonly)

test_file = self.tempfile("temp.ppm")
im._dump(test_file)
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"))

def test_comparison_with_other_type(self):
# Arrange
Expand Down
1 change: 1 addition & 0 deletions src/libImaging/File.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ ImagingSavePPM(Imaging im, const char* outfile)
/* Write "PPM" */
fprintf(fp, "P6\n%d %d\n255\n", im->xsize, im->ysize);
} else {
fclose(fp);
(void) ImagingError_ModeError();
return 0;
}
Expand Down

0 comments on commit 8cc9713

Please sign in to comment.