Bug in HTTimer.c

Hi,

I'm very sure that I found a bug in HTTimer.c. It does only concern Win32 applications in Async mode:

When a timer event happens, it is dispatched by the event loop and the hidden window procedure from the event loop procedure. In Timer_dispatch(..), the event is removed from the event list in case it is not a repetitive event. The procedure calls HTList_quickRemoveElement() to get rid of the event. However, on Win32, events triggered by SetTimer() are always repetitive, so that one has to call KillTimer() to get rid of the corresponding WM_TIMER messages. Thus, the code has to be changed to:

>    if (timer->repetitive)
> HTTimer_new(timer, timer->cbf, timer->param, timer->millis, YES, YES);
>    else
> HTList_quickRemoveElement(cur, last);
#ifdef WWW_WIN_ASYNC
 // on windows we have to stop the timer 
 DeletePlatformTimer(timer);
#endif
>    HTTRACE(THD_TRACE, "Timer....... Dispatch timer %p\n" _ timer);
>    ret = (*timer->cbf) (timer, timer->param, HTEvent_TIMEOUT);
>    return ret;

The bug is not really dangerous to you applications. Whithout the patch, your application gets slower after each HTTP request. When a single request is finished, the timer remains in the system and occurs 100 times per second. When dispatched, no procedure is called because the attached timer pointer is NULL. This code is located in Timer_dispatch():

if (timer == NULL) {
#if 0
        HTDEBUGBREAK("Timer dispatch couldn't find a timer\n");
#endif
        CLEARME(timer);
 return HT_ERROR;
    }

Thus, Timer_dispatch() always returns HT_ERROR for each timer that has not been killed. When writing a robot or a server, this can become a huge portion of CPU resources.

Please give some feedback when you think I'm wrong.

Best regards,

Jens

Received on Thursday, 13 July 2000 11:33:57 UTC