changeset 1023:e719ee25439d

Fix potential use of freed memory in the threaded timer system
author Sam Lantinga <slouken@libsdl.org>
date Tue, 04 Jan 2005 19:05:32 +0000
parents 3d4f1930ed02
children cca9aeb2934f
files src/timer/SDL_timer.c
diffstat 1 files changed, 8 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/timer/SDL_timer.c	Tue Jan 04 19:04:14 2005 +0000
+++ b/src/timer/SDL_timer.c	Tue Jan 04 19:05:32 2005 +0000
@@ -45,7 +45,7 @@
 Uint32 SDL_alarm_interval = 0;
 SDL_TimerCallback SDL_alarm_callback;
 
-static SDL_bool list_changed = SDL_FALSE;
+static volatile SDL_bool list_changed = SDL_FALSE;
 
 /* Data used for a thread-based timer */
 static int SDL_timer_threaded = 0;
@@ -114,6 +114,9 @@
 	Uint32 now, ms;
 	SDL_TimerID t, prev, next;
 	int removed;
+	SDL_NewTimerCallback callback;
+	Uint32 interval;
+	void *param;
 
 	now = SDL_GetTicks();
 
@@ -133,8 +136,11 @@
 			printf("Executing timer %p (thread = %d)\n",
 						t, SDL_ThreadID());
 #endif
+			callback = t->cb;
+			interval = t->interval;
+			param = t->param;
 			SDL_mutexV(SDL_timer_mutex);
-			ms = t->cb(t->interval, t->param);
+			ms = callback(interval, param);
 			SDL_mutexP(SDL_timer_mutex);
 			if ( list_changed ) {
 				/* Abort, list of timers has been modified */