timer_create gives memory leaks issue "Syscall param timer_create(evp) points to uninitialised byte(s)"
struct sigevent t开发者_如何学编程imerEvent;
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");
}
Memory Leak, the following denotes
Syscall param timer_create(evp) points to uninitialised byte(s)
==27384== at 0x530595: timer_create (in /lib/librt-2.5.so)
This seems to be a known valgrind issue:
http://bugs.kde.org/show_bug.cgi?id=124478
...and...
http://www.google.co.uk/search?source=ig&hl=en&rlz=&q=Syscall+param+timer_create%28evp%29+points+to+uninitialised+byte%28s%29&btnG=Google+Search
Had the same problem and made valgrind happy with this:
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);
I used this as a reference: http://pubs.opengroup.org/onlinepubs/7908799/xsh/timer_create.html
This looks pretty uninitialzed to me:
timer_t timer_ID;
You are memset
ing the timerEvent
but not his one.
精彩评论