Fix potential use of freed memory in the threaded timer system
authorSam Lantinga <slouken@libsdl.org>
Tue, 04 Jan 2005 19:05:32 +0000
changeset 1023e719ee25439d
parent 1022 3d4f1930ed02
child 1024 cca9aeb2934f
Fix potential use of freed memory in the threaded timer system
src/timer/SDL_timer.c
     1.1 --- a/src/timer/SDL_timer.c	Tue Jan 04 19:04:14 2005 +0000
     1.2 +++ b/src/timer/SDL_timer.c	Tue Jan 04 19:05:32 2005 +0000
     1.3 @@ -45,7 +45,7 @@
     1.4  Uint32 SDL_alarm_interval = 0;
     1.5  SDL_TimerCallback SDL_alarm_callback;
     1.6  
     1.7 -static SDL_bool list_changed = SDL_FALSE;
     1.8 +static volatile SDL_bool list_changed = SDL_FALSE;
     1.9  
    1.10  /* Data used for a thread-based timer */
    1.11  static int SDL_timer_threaded = 0;
    1.12 @@ -114,6 +114,9 @@
    1.13  	Uint32 now, ms;
    1.14  	SDL_TimerID t, prev, next;
    1.15  	int removed;
    1.16 +	SDL_NewTimerCallback callback;
    1.17 +	Uint32 interval;
    1.18 +	void *param;
    1.19  
    1.20  	now = SDL_GetTicks();
    1.21  
    1.22 @@ -133,8 +136,11 @@
    1.23  			printf("Executing timer %p (thread = %d)\n",
    1.24  						t, SDL_ThreadID());
    1.25  #endif
    1.26 +			callback = t->cb;
    1.27 +			interval = t->interval;
    1.28 +			param = t->param;
    1.29  			SDL_mutexV(SDL_timer_mutex);
    1.30 -			ms = t->cb(t->interval, t->param);
    1.31 +			ms = callback(interval, param);
    1.32  			SDL_mutexP(SDL_timer_mutex);
    1.33  			if ( list_changed ) {
    1.34  				/* Abort, list of timers has been modified */