Bug 124478

Summary: memcheck reports uninitialized bytes on timer_create() while it should not
Product: [Developer tools] valgrind Reporter: Bart Van Assche <bart.vanassche+kde>
Component: memcheckAssignee: Julian Seward <jseward>
Status: CLOSED WORKSFORME    
Severity: normal CC: trapni
Priority: NOR    
Version: 3.1.1   
Target Milestone: ---   
Platform: Compiled Sources   
OS: Linux   
Latest Commit: Version Fixed In:

Description Bart Van Assche 2006-03-29 09:54:08 UTC
OS: SuSE 9.2 (2.6.8 kernel) on i386
Valgrind output:
==22113== Memcheck, a memory error detector.
==22113== Copyright (C) 2002-2005, and GNU GPL'd, by Julian Seward et al.
==22113== Using LibVEX rev 1575, a library for dynamic binary translation.
==22113== Copyright (C) 2004-2005, and GNU GPL'd, by OpenWorks LLP.
==22113== Using valgrind-3.1.1, a dynamic binary instrumentation framework.
==22113== Copyright (C) 2000-2005, and GNU GPL'd, by Julian Seward et al.
==22113== For more details, rerun with: -v
==22113==
==22113== Syscall param timer_create(evp) points to uninitialised byte(s)
==22113==    at 0x403353E: timer_create (in /lib/tls/librt.so.1)
==22113==    by 0x8048674: main (in /home/vanassb/test/highrestimer/i386-hrtimer)
==22113==  Address 0xBEFFF1DC is on thread 1's stack

Test program:
#include <cassert>
#include <cstring>
#include <time.h>
#include <unistd.h>
#include <signal.h>

#define VERIFY(e) assert(e)

static void TimerHandler(sigval_t)
{
  write(STDOUT_FILENO, "timer\n", 6);
}

int main(int argc, char** argv)
{
  sigevent ev;
  memset(&ev, 0, sizeof(ev));
  ev.sigev_notify = SIGEV_THREAD;
  ev.sigev_notify_function = TimerHandler;
  ev.sigev_notify_attributes = NULL;
  ev.sigev_value.sival_ptr = 0;
  timer_t timer;
  VERIFY(timer_create(CLOCK_REALTIME, &ev, &timer) >= 0);
  itimerspec const timervalue = {
    it_interval: { 1, 0 },
    it_value:    { 0, 500*1000*1000 }
  };
  VERIFY(timer_settime(timer, 0, &timervalue, 0) >= 0);
  sleep(5);
  VERIFY(timer_delete(timer) >= 0);
  return 0;
}

// Local variables:
// compile-command: "ARGS='-Wall -W -Wno-unused-parameter hrtimer.cpp -lrt' &&
g++ -o i386-hrtimer $ARGS && ppc_440-g++ -o ppc-hrtimer $ARGS"
// End:
Comment 1 Tom Hughes 2006-03-30 10:00:16 UTC
The problem is that glibc converts SIGEV_THREAD into SIGEV_SIGNAL by spawning a thread and then doing a SIGEV_SIGNAL timer_create call in the new thread. The sigevent structure that glibc builds in that new thread includes uninitialised data so valgrind is strictly speaking correct (the uninitialised data is padding so won't actually affect anything).
Comment 2 Christian Parpart 2006-12-26 16:08:04 UTC
you might throw this back to valgrind, as it is checking padding bytes that are never read from.

so it would be nice to see valgrind enheanced in a way it won't complain about this anymore. is this possible?
Comment 3 Bart Van Assche 2007-10-25 16:40:17 UTC
Has been solved in glibc. See also
http://sources.redhat.com/bugzilla/show_bug.cgi?id=4306