The context is a daemon started from inittab; this daemon spawns pthreads. A pthread can invoke putenv(), fork(), execve(). Valgrind reports invalid reads on the first environment variable (__environ[0]="PWD=/"); examples provided below. I wrote a very simple program which demonstrates that, when fork/exec is invoked outside pthreads, valgrind does not report errors. When invoked from within pthreads, it reports the errors.I'll try to attach the tarfile of the sources. Linux Debian ... # uname -a Linux 2.4.26-acopia15 #1 SMP Fri Oct 22 21:58:40 EDT 2004 i686 unknown # valgrind --version valgrind-2.2.0 Examples invalid reads: ==753== Thread 3: ==753== Invalid read of size 1 ==753== at 0x1B8FF8F4: strncmp (mac_replace_strmem.c:233) ==753== by 0x1BB996D4: __add_to_environ (../sysdeps/generic/setenv.c:131) ==753== by 0x1BB9962C: putenv (../sysdeps/generic/putenv.c:67) ==753== by 0x8056F9B: ??? (system.c:56) ==753== by 0x8054F95: ??? (svc_agent_processor.c:188) ==753== by 0x8055AC4: ??? (svc_agent_processor.c:832) ==753== by 0x8055FCC: ??? (svc_agent_processor.c:1069) ==753== by 0x8056959: ??? (svc_agent_processor.c:1628) ==753== by 0x1B9AE999: thread_wrapper (vg_libpthread.c:867) ==753== by 0xB000F0BF: (within /usr/lib/valgrind/stage2) ==753== Address 0x52BFEEB6 is not stack'd, malloc'd or (recently) free'd ==753== ==753== Thread 3: ==753== Syscall param execve(envp[i]) contains uninitialised or unaddressable byte(s) ==753== at 0x1BC0EF06: execve (../sysdeps/unix/sysv/linux/execve.c:70) ==753== by 0x8056FF5: ??? (system.c:71) ==753== by 0x8054F95: ??? (svc_agent_processor.c:188) ==753== by 0x8055AC4: ??? (svc_agent_processor.c:832) ==753== by 0x8055FCC: ??? (svc_agent_processor.c:1069) ==753== by 0x8056959: ??? (svc_agent_processor.c:1628) ==753== by 0x1B9AE999: thread_wrapper (vg_libpthread.c:867) ==753== by 0xB000F0BF: (within /usr/lib/valgrind/stage2) ==753== Address 0x52BFEEB6 is not stack'd, malloc'd or (recently) free'd
Created attachment 8182 [details] bug demonstration code Attaching example code. Thanks.
There is some sort of problem with the way the environment is handled on fork/exec but I've never been able to work out what is causing it. There's already a bug for it anyway so I'm going to join this to it - your new information about it only happening with pthreads is certainly interesting. *** This bug has been marked as a duplicate of 85625 ***