Mercurial > hg > dmlib
changeset 1787:8af6067b6bd7
Actually it seems to be good to NULL check before calling SDL_Destroy*() and
free functions. According to Valgrind SDL2 "leaks" memory with its error message
setting if you give NULL pointers, although this is pretty harmless.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Wed, 13 Jun 2018 01:46:18 +0300 |
parents | 52e90130453b |
children | 04e13949b314 |
files | tools/64vw.c tools/ppl.c |
diffstat | 2 files changed, 21 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/tools/64vw.c Wed Jun 13 01:40:22 2018 +0300 +++ b/tools/64vw.c Wed Jun 13 01:46:18 2018 +0300 @@ -534,10 +534,17 @@ // Cleanup dmFree(optFilenames); - SDL_DestroyWindow(window); - SDL_DestroyTexture(texture); - SDL_FreeSurface(surf); + if (texture != NULL) + SDL_DestroyTexture(texture); + + if (renderer != NULL) + SDL_DestroyRenderer(renderer); + if (window != NULL) + SDL_DestroyWindow(window); + + if (surf != NULL) + SDL_FreeSurface(surf); if (initSDL) SDL_Quit();
--- a/tools/ppl.c Wed Jun 13 01:40:22 2018 +0300 +++ b/tools/ppl.c Wed Jun 13 01:46:18 2018 +0300 @@ -910,10 +910,17 @@ } error_exit: - SDL_DestroyTexture(engine.texture); - SDL_DestroyRenderer(engine.renderer); - SDL_DestroyWindow(engine.window); - SDL_FreeSurface(engine.screen); + if (engine.texture != NULL) + SDL_DestroyTexture(engine.texture); + + if (engine.renderer != NULL) + SDL_DestroyRenderer(engine.renderer); + + if (engine.window != NULL) + SDL_DestroyWindow(engine.window); + + if (engine.screen != NULL) + SDL_FreeSurface(engine.screen); dmMsg(0, "Audio shutdown.\n"); if (audioInit)