comparison src/timer/SDL_timer.c @ 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 e8157fcb3114
children 5ba65305c954
comparison
equal deleted inserted replaced
1022:3d4f1930ed02 1023:e719ee25439d
43 43
44 /* Data to handle a single periodic alarm */ 44 /* Data to handle a single periodic alarm */
45 Uint32 SDL_alarm_interval = 0; 45 Uint32 SDL_alarm_interval = 0;
46 SDL_TimerCallback SDL_alarm_callback; 46 SDL_TimerCallback SDL_alarm_callback;
47 47
48 static SDL_bool list_changed = SDL_FALSE; 48 static volatile SDL_bool list_changed = SDL_FALSE;
49 49
50 /* Data used for a thread-based timer */ 50 /* Data used for a thread-based timer */
51 static int SDL_timer_threaded = 0; 51 static int SDL_timer_threaded = 0;
52 52
53 struct _SDL_TimerID { 53 struct _SDL_TimerID {
112 void SDL_ThreadedTimerCheck(void) 112 void SDL_ThreadedTimerCheck(void)
113 { 113 {
114 Uint32 now, ms; 114 Uint32 now, ms;
115 SDL_TimerID t, prev, next; 115 SDL_TimerID t, prev, next;
116 int removed; 116 int removed;
117 SDL_NewTimerCallback callback;
118 Uint32 interval;
119 void *param;
117 120
118 now = SDL_GetTicks(); 121 now = SDL_GetTicks();
119 122
120 SDL_mutexP(SDL_timer_mutex); 123 SDL_mutexP(SDL_timer_mutex);
121 for ( prev = NULL, t = SDL_timers; t; t = next ) { 124 for ( prev = NULL, t = SDL_timers; t; t = next ) {
131 list_changed = SDL_FALSE; 134 list_changed = SDL_FALSE;
132 #ifdef DEBUG_TIMERS 135 #ifdef DEBUG_TIMERS
133 printf("Executing timer %p (thread = %d)\n", 136 printf("Executing timer %p (thread = %d)\n",
134 t, SDL_ThreadID()); 137 t, SDL_ThreadID());
135 #endif 138 #endif
139 callback = t->cb;
140 interval = t->interval;
141 param = t->param;
136 SDL_mutexV(SDL_timer_mutex); 142 SDL_mutexV(SDL_timer_mutex);
137 ms = t->cb(t->interval, t->param); 143 ms = callback(interval, param);
138 SDL_mutexP(SDL_timer_mutex); 144 SDL_mutexP(SDL_timer_mutex);
139 if ( list_changed ) { 145 if ( list_changed ) {
140 /* Abort, list of timers has been modified */ 146 /* Abort, list of timers has been modified */
141 break; 147 break;
142 } 148 }