[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [pygame] A question...



> In the load method for image I find the following code with the troubling
> sequence of action
> 
> -> allocate some data dynamically put it in surf
> -> return new_object_built from surf
> 
> My question is as PySurface_New does not deallocate the surface passed as a
> parameter if the allocation of the Python object for the surface fails, we
> are going to have a memory leak aren't we?

yes, it looks like there is a case for the surface to be leaked.
the only time PySurface_New will leak memory is if it fails to
allocate a PyObject structure. but, if this does happen, the
python interpreter will have already raised the MemoryError
exception. the program will likely quit then anyways because of
the excpetion (unless MemoryError is being handled)
on some platforms i've noticed that when running out of memory
the system will kill the process anyways.

so in all the usual cases the program will come to an end anyways
once there is a problem in the PySurface_New. and one shouldn't
expect the system to always recover from a malloc error.

in any case, it is easy enough for PySurface_New to make sure the
surface passed to it is freed if a problem does happen. i'll get
this in for the next version, but nobody needs to worry about this
sort of situation leaking memory on them without them knowing.


____________________________________
pygame mailing list
pygame-users@seul.org
http://pygame.seul.org