Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
Fixed crash if SDL_GetThreadName() is passed a NULL thread.
Browse files Browse the repository at this point in the history
  • Loading branch information
slouken committed Aug 8, 2013
1 parent 391ace6 commit 2bfe7ce
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions src/thread/SDL_thread.c
Expand Up @@ -319,7 +319,9 @@ SDL_CreateThread(int (SDLCALL * fn) (void *),
args = (thread_args *) SDL_malloc(sizeof(*args));
if (args == NULL) {
SDL_OutOfMemory();
SDL_free(thread->name);
if (thread->name) {
SDL_free(thread->name);
}
SDL_free(thread);
return (NULL);
}
Expand All @@ -328,7 +330,9 @@ SDL_CreateThread(int (SDLCALL * fn) (void *),
args->info = thread;
args->wait = SDL_CreateSemaphore(0);
if (args->wait == NULL) {
SDL_free(thread->name);
if (thread->name) {
SDL_free(thread->name);
}
SDL_free(thread);
SDL_free(args);
return (NULL);
Expand All @@ -345,7 +349,9 @@ SDL_CreateThread(int (SDLCALL * fn) (void *),
SDL_SemWait(args->wait);
} else {
/* Oops, failed. Gotta free everything */
SDL_free(thread->name);
if (thread->name) {
SDL_free(thread->name);
}
SDL_free(thread);
thread = NULL;
}
Expand All @@ -372,7 +378,11 @@ SDL_GetThreadID(SDL_Thread * thread)
const char *
SDL_GetThreadName(SDL_Thread * thread)
{
return thread->name;
if (thread) {
return thread->name;
} else {
return NULL;
}
}

int
Expand All @@ -389,7 +399,9 @@ SDL_WaitThread(SDL_Thread * thread, int *status)
if (status) {
*status = thread->status;
}
SDL_free(thread->name);
if (thread->name) {
SDL_free(thread->name);
}
SDL_free(thread);
}
}
Expand Down

0 comments on commit 2bfe7ce

Please sign in to comment.