From: Marcus M. <cod...@gm...> - 2012-04-09 20:10:51
|
Hello Michael, hello Mattia, [Michael Reinelt] > > What I currently do not understand: why would somebody do a > > malloc(sizeof(int)) ?? [Mattia Jona-Lasinio] > I totally agree :) and the answer is: I have no idea :) > > The only reason I see is that when calling > timer_add(timer_process_group, TimerGroups[group].interval, interval, > 0) in timer_group.c, the time interval is passed as the argument of > the callback function. But we can make the interval member in the > TIMER_GROUP structure an int instead of int* and rewrite > timer_add(timer_process_group, &TimerGroups[group].interval, interval, > 0). I haven't seen it on March 26, too. But now I think the int*/malloc for the 'interval' element is very important: The realloc in 'timer_add_group' could change the positions of all already existing 'TimerGroups' (and their elements like 'interval') AFTER the pointer to their 'interval' elements were given to the timers via previous 'timer_add' calls. This will cause problems when 'timer_process' is called which will use the old addresses. Ticket #281 (Segmentation fault) might be a result of that. The int*/malloc-trick (or linked lists ;) ) avoid that problem. Regards Marcus -- NEU: FreePhone 3-fach-Flat mit kostenlosem Smartphone! Jetzt informieren: http://mobile.1und1.de/?ac=OM.PW.PW003K20328T7073a |