ResourceWarning: unclosed file for pygame_icon.bmp

Issue #165 closed
Lenard Lindstrom created an issue

Python3.3-dbg on Linux Mint 14 Nadia

The unit test raises a ResourceWarning when executing line

screen = pygame.display.set_mode((640, 480))

in SurfaceFillTest.test_fill(). The icon file is not explicitly closed. Since reference counting is not guaranteed for future C Python interpreters this should be fixed.

Comments (5)

  1. René Dudfield

    Investigation of display.c for font loading lead me to image.c and pygame.image.load_basic.

    It seems image.c frees the file in the load_basic function "surf = SDL_LoadBMP_RW (rw, 1);" The 1 argument frees the stream when done loading. The the icon file should be closed.

    I tried adding "icon_was_set = 0;" to display.c in commit ee208d8. Which should make it try to set the icon again if it is quit first. Which I think is appropriate.

    That's all I looked into, since I'm not currently on a linux box.

  2. Lenard Lindstrom reporter

    Close Issue #165

    The icon file is opened as a Python file object to check if it exists, and, presumably, to retrieve it's full path name. Then the file object is released, and replaced with the path name, a Python string. The string is passed to pygame.image.load_basic() to retrieve the icon image. This patch adds a close() method call on the file object before it is released.

    → <<cset 3b3ba7749842>>

  3. Log in to comment