Fixed crash if SDL_GetThreadName() is passed a NULL thread.
authorSam Lantinga
Thu, 08 Aug 2013 12:21:26 -0700
changeset 7606bb2aa25cca1c
parent 7605 7a47881c2800
child 7607 7753a6f8cda8
Fixed crash if SDL_GetThreadName() is passed a NULL thread.
src/thread/SDL_thread.c
     1.1 --- a/src/thread/SDL_thread.c	Thu Aug 08 12:20:22 2013 -0700
     1.2 +++ b/src/thread/SDL_thread.c	Thu Aug 08 12:21:26 2013 -0700
     1.3 @@ -319,7 +319,9 @@
     1.4      args = (thread_args *) SDL_malloc(sizeof(*args));
     1.5      if (args == NULL) {
     1.6          SDL_OutOfMemory();
     1.7 -        SDL_free(thread->name);
     1.8 +        if (thread->name) {
     1.9 +            SDL_free(thread->name);
    1.10 +        }
    1.11          SDL_free(thread);
    1.12          return (NULL);
    1.13      }
    1.14 @@ -328,7 +330,9 @@
    1.15      args->info = thread;
    1.16      args->wait = SDL_CreateSemaphore(0);
    1.17      if (args->wait == NULL) {
    1.18 -        SDL_free(thread->name);
    1.19 +        if (thread->name) {
    1.20 +            SDL_free(thread->name);
    1.21 +        }
    1.22          SDL_free(thread);
    1.23          SDL_free(args);
    1.24          return (NULL);
    1.25 @@ -345,7 +349,9 @@
    1.26          SDL_SemWait(args->wait);
    1.27      } else {
    1.28          /* Oops, failed.  Gotta free everything */
    1.29 -        SDL_free(thread->name);
    1.30 +        if (thread->name) {
    1.31 +            SDL_free(thread->name);
    1.32 +        }
    1.33          SDL_free(thread);
    1.34          thread = NULL;
    1.35      }
    1.36 @@ -372,7 +378,11 @@
    1.37  const char *
    1.38  SDL_GetThreadName(SDL_Thread * thread)
    1.39  {
    1.40 -    return thread->name;
    1.41 +    if (thread) {
    1.42 +        return thread->name;
    1.43 +    } else {
    1.44 +        return NULL;
    1.45 +    }
    1.46  }
    1.47  
    1.48  int
    1.49 @@ -389,7 +399,9 @@
    1.50          if (status) {
    1.51              *status = thread->status;
    1.52          }
    1.53 -        SDL_free(thread->name);
    1.54 +        if (thread->name) {
    1.55 +            SDL_free(thread->name);
    1.56 +        }
    1.57          SDL_free(thread);
    1.58      }
    1.59  }