-
setitimer() memory leaks
Hey I wanted to know since i used this test portion of code to continously have a repetitive timer.
Code:
void alarm_wakeup (int i)
{
struct itimerval tout_val;
signal(SIGALRM,alarm_wakeup);
howmany += INTERVAL;
printf("\n%d sec up partner, Wakeup!!!\n",howmany);
tout_val.it_interval.tv_sec = 0;
tout_val.it_interval.tv_usec = 0;
tout_val.it_value.tv_sec = INTERVAL; /* 10 seconds timer */
tout_val.it_value.tv_usec = 0;
setitimer(ITIMER_REAL, &tout_val,0);
}
That will constanly wake up at every interval does settimer() delete the struct tout_val after it goes off or do i need to free the struct somewhere? I know theres no malloc anywhere in the code but since im declaring the struct over and over everytime does that mean I need to free it?
-
If you didn't malloc it, you can't free it. The struct is on the stack, and will be removed when the stack goes away (when the function ends).