fix sdl memory leak

This commit is contained in:
lixianjing 2021-02-26 14:46:26 +08:00
parent e296dcfe7e
commit 9b210a0ae4
4 changed files with 11 additions and 5 deletions

View File

@ -297,6 +297,8 @@ extern DECLSPEC void * SDLCALL SDL_TLSGet(SDL_TLSID id);
*/
extern DECLSPEC int SDLCALL SDL_TLSSet(SDL_TLSID id, const void *value, void (SDLCALL *destructor)(void*));
extern DECLSPEC void SDLCALL SDL_TLSCleanup();
/* Ends C function definitions when using C++ */
#ifdef __cplusplus

View File

@ -83,7 +83,7 @@ SDL_TLSSet(SDL_TLSID id, const void *value, void (SDLCALL *destructor)(void *))
return 0;
}
static void
void
SDL_TLSCleanup()
{
SDL_TLSData *storage;

View File

@ -2871,6 +2871,7 @@ SDL_VideoQuit(void)
_this->displays = NULL;
_this->num_displays = 0;
}
SDL_TLSCleanup();
SDL_free(_this->clipboard_text);
_this->clipboard_text = NULL;
_this->free(_this);

View File

@ -163,10 +163,6 @@ static ret_t native_window_sdl_close(native_window_t* win) {
SDL_DestroyRenderer(sdl->render);
}
if (sdl->window != NULL) {
SDL_DestroyWindow(sdl->window);
}
if (sdl->context != NULL) {
SDL_GL_DeleteContext(sdl->context);
}
@ -605,6 +601,13 @@ ret_t native_window_sdl_init(bool_t shared, uint32_t w, uint32_t h) {
ret_t native_window_sdl_deinit(void) {
if (s_shared_win != NULL) {
native_window_sdl_t* sdl = NATIVE_WINDOW_SDL(s_shared_win);
if (sdl->cursor_surface != NULL) {
SDL_FreeSurface(sdl->cursor_surface);
sdl->cursor_surface = NULL;
}
object_unref(OBJECT(s_shared_win));
s_shared_win = NULL;
}