Fixed bug 3790 - Memory leak with surfaces blitting on each other
bastien.bouclet When creating two surfaces and blitting them onto the other, SDL's internal reference counting fails, and one of the surfaces is not freed when calling SDL_FreeSurface. Example code : SDL_Surface *s1 = SDL_CreateRGBSurfaceWithFormat(0, 640, 480, 32, SDL_PIXELFORMAT_ARGB8888); SDL_Surface *s2 = SDL_CreateRGBSurfaceWithFormat(0, 640, 480, 32, SDL_PIXELFORMAT_ARGB8888); SDL_BlitSurface(s1, NULL, s2, NULL); SDL_BlitSurface(s2, NULL, s1, NULL); SDL_FreeSurface(s2); SDL_FreeSurface(s1); With this example, s1 is not freed after calling SDL_FreeSurface, its refcount attribute is still positive.
parent
532446a6bd
commit
67f9348baa
|
@ -1193,6 +1193,10 @@ SDL_FreeSurface(SDL_Surface * surface)
|
||||||
if (surface->flags & SDL_DONTFREE) {
|
if (surface->flags & SDL_DONTFREE) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (surface->map != NULL) {
|
||||||
|
SDL_FreeBlitMap(surface->map);
|
||||||
|
surface->map = NULL;
|
||||||
|
}
|
||||||
if (--surface->refcount > 0) {
|
if (--surface->refcount > 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -1207,10 +1211,6 @@ SDL_FreeSurface(SDL_Surface * surface)
|
||||||
SDL_FreeFormat(surface->format);
|
SDL_FreeFormat(surface->format);
|
||||||
surface->format = NULL;
|
surface->format = NULL;
|
||||||
}
|
}
|
||||||
if (surface->map != NULL) {
|
|
||||||
SDL_FreeBlitMap(surface->map);
|
|
||||||
surface->map = NULL;
|
|
||||||
}
|
|
||||||
if (!(surface->flags & SDL_PREALLOC)) {
|
if (!(surface->flags & SDL_PREALLOC)) {
|
||||||
SDL_free(surface->pixels);
|
SDL_free(surface->pixels);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue