Hullo, I hope someone can help? I have this C code:
It "works" and reports no error, but when I run it under valgrind, it says:
The only lead I have is that if the semaphore already exists when the program starts, the valgrind error goes away. What am I doing wrong?
Thank you.
C:
#include <stdio.h>
#include <errno.h>
#include <stdlib.h>
#include <unistd.h>
#include <semaphore.h>
#include <fcntl.h>
int main(void)
{
errno = 0;
sem_t *s = sem_open("/lala",O_CREAT,0777,0);
perror("Our error?");
sem_close(s);
sem_unlink("/lala");
}
It "works" and reports no error, but when I run it under valgrind, it says:
Code:
username@freebsd:~/horrorshow $ valgrind --track-origins=yes -s ./a.out
==19415== Memcheck, a memory error detector
==19415== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==19415== Using Valgrind-3.17.0 and LibVEX; rerun with -h for copyright info
==19415== Command: ./a.out
==19415==
==19415== Syscall param write(buf) points to uninitialised byte(s)
==19415== at 0x499680A: _write (in /lib/libc.so.7)
==19415== by 0x4913551: sem_open (in /lib/libc.so.7)
==19415== by 0x2019EF: main (in /usr/home/username/horrorshow/a.out)
==19415== Address 0x7fc0003fc is on thread 1's stack
==19415== in frame #1, created by sem_open (???:)
==19415== Uninitialised value was created by a stack allocation
==19415== at 0x49132ED: sem_open (in /lib/libc.so.7)
==19415==
Our error?: No error: 0
==19415==
==19415== HEAP SUMMARY:
==19415== in use at exit: 63 bytes in 3 blocks
==19415== total heap usage: 6 allocs, 3 frees, 230 bytes allocated
==19415==
==19415== LEAK SUMMARY:
==19415== definitely lost: 0 bytes in 0 blocks
==19415== indirectly lost: 0 bytes in 0 blocks
==19415== possibly lost: 0 bytes in 0 blocks
==19415== still reachable: 63 bytes in 3 blocks
==19415== suppressed: 0 bytes in 0 blocks
==19415== Rerun with --leak-check=full to see details of leaked memory
==19415==
==19415== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)
==19415==
==19415== 1 errors in context 1 of 1:
==19415== Syscall param write(buf) points to uninitialised byte(s)
==19415== at 0x499680A: _write (in /lib/libc.so.7)
==19415== by 0x4913551: sem_open (in /lib/libc.so.7)
==19415== by 0x2019EF: main (in /usr/home/username/horrorshow/a.out)
==19415== Address 0x7fc0003fc is on thread 1's stack
==19415== in frame #1, created by sem_open (???:)
==19415== Uninitialised value was created by a stack allocation
==19415== at 0x49132ED: sem_open (in /lib/libc.so.7)
==19415==
==19415== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)
The only lead I have is that if the semaphore already exists when the program starts, the valgrind error goes away. What am I doing wrong?
Thank you.
Last edited by a moderator: