struct sigevent timerEvent;
memset(&timerEvent, 0, sizeof(timerEvent));
timerEvent.sigev_value.sival_int = 0;
timerEvent.sigev_value.sival_ptr = diaBase;
timerEvent.sigev_notify = SIGEV_THREAD;
timerEvent._sigev_un._sigev_thread._function = function;
timerEvent._sigev_un._sigev_thread._attribute = NULL;
timer_t timer_ID;
int retVal;
if((retVal = timer_create (CLOCK_REALTIME, &timerEvent, &timer_ID )) != -1)
{
printf("Timer Created Successfully: %ld\n", timer_ID );
}
else
{
printf("Error Creating Timer\n");
}
内存泄漏,以下表示
Syscall param timer_create(evp) points to uninitialised byte(s)
==27384== at 0x530595: timer_create (in /lib/librt-2.5.so)
答案 0 :(得分:5)
答案 1 :(得分:1)
有同样的问题,让valgrind对此表示满意:
timer_t timerId;
struct sigevent* sigev = static_cast<struct sigevent*>(calloc(1, sizeof(struct sigevent)));
sigev->sigev_notify = SIGEV_SIGNAL;
sigev->sigev_signo = SIGALRM;
sigev->sigev_value.sival_ptr = &timerId;
timer_create(CLOCK_REALTIME, sigev, &timerId);
// Use the timer
...
// After totally done with the timer
free(sigev);
我用它作为参考:http://pubs.opengroup.org/onlinepubs/7908799/xsh/timer_create.html
答案 2 :(得分:0)
这对我来说看起来很未初始化:
timer_t timer_ID;
memset
中的timerEvent
,而不是{{1}}。