From 2621ffabcb5d4b0f5631c898e42c7f1e6e24c849 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Thu, 11 Apr 2002 21:08:44 +0000 Subject: [PATCH] Fixed a minor memory leak in the SDL thread subsystem --- src/thread/SDL_thread.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/thread/SDL_thread.c b/src/thread/SDL_thread.c index 645d48e07..2cb373fa3 100644 --- a/src/thread/SDL_thread.c +++ b/src/thread/SDL_thread.c @@ -146,10 +146,15 @@ static void SDL_DelThread(SDL_Thread *thread) } } if ( i < SDL_numthreads ) { - --SDL_numthreads; - while ( i < SDL_numthreads ) { - SDL_Threads[i] = SDL_Threads[i+1]; - ++i; + if ( --SDL_numthreads > 0 ) { + while ( i < SDL_numthreads ) { + SDL_Threads[i] = SDL_Threads[i+1]; + ++i; + } + } else { + SDL_maxthreads = 0; + free(SDL_Threads); + SDL_Threads = NULL; } #ifdef DEBUG_THREADS printf("Deleting thread (%d left - %d max)\n",