C - sigqueue 调用时 Valgrind 报告 "Syscall param points to uninitialised byte"

标签 c valgrind sigqueue

有一个程序,其中子进程需要向父亲发送一些信号。然而,valgrind 对 sigqueue 调用大喊大叫。已经阅读了一段时间,但找不到答案。

这是子进程的作用:

void cajero(int id){
    FILE *fp, *fp_caja;
    char filename[MAXBUFF], filename_caja[MAXBUFF], price[8];
    float p;
    union sigval val;
    bool booleano;

    ...

    val.sival_int = id;

    while(fgets(price, sizeof(price), fp)){
        p = atof(price);

        ...

        sigqueue(getppid(), SIGMONEY, val); //sigqueue Call

    }
    ...

    sigqueue(getppid(), SIGDONE, val); //sigqueue Call
    fclose(fp);
    exit(EXIT_SUCCESS);
}

这是一个 child 的 valgrind 报告(它在内部 sigqueue 中进行了两次调用,在外部进行了一次调用:

==14688== HEAP SUMMARY:
==14688==     in use at exit: 0 bytes in 0 blocks
==14688==   total heap usage: 48 allocs, 48 frees, 107,460 bytes allocated
==14688== 
==14688== All heap blocks were freed -- no leaks are possible
==14688== 
==14688== ERROR SUMMARY: 3 errors from 2 contexts (suppressed: 0 from 0)
==14688== 
==14688== 1 errors in context 1 of 2:
==14688== Syscall param rt_sigqueueinfo(uinfo) points to uninitialised byte(s)
==14688==    at 0x508DBE4: sigqueue (sigqueue.c:43)
==14688==    by 0x401B3A: cajero (ejercicio9.c:316)
==14688==    by 0x40130C: main (ejercicio9.c:181)
==14688==  Address 0xffefff67c is on thread 1's stack
==14688==  in frame #0, created by sigqueue (sigqueue.c:30)
==14688==  Uninitialised value was created by a stack allocation
==14688==    at 0x4018D7: cajero (ejercicio9.c:284)
==14688== 
==14688== 
==14688== 2 errors in context 2 of 2:
==14688== Syscall param rt_sigqueueinfo(uinfo) points to uninitialised byte(s)
==14688==    at 0x508DBE4: sigqueue (sigqueue.c:43)
==14688==    by 0x401AC1: cajero (ejercicio9.c:311)
==14688==    by 0x40130C: main (ejercicio9.c:181)
==14688==  Address 0xffefff67c is on thread 1's stack
==14688==  in frame #0, created by sigqueue (sigqueue.c:30)
==14688==  Uninitialised value was created by a stack allocation
==14688==    at 0x4018D7: cajero (ejercicio9.c:284)
==14688== 
==14688== ERROR SUMMARY: 3 errors from 2 contexts (suppressed: 0 from 0)

提前致谢。我现在已经脑死亡了。

编辑:SIGMONEY 和 SIGDONE 分别是 SIGRTMIN 和 SIGRTMIN+1。

最佳答案

您没有初始化“val” union 。只需更改声明即可:

union sigval val = {0};

关于C - sigqueue 调用时 Valgrind 报告 "Syscall param points to uninitialised byte",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49683742/

相关文章:

c - 使用 sigqueue 和 SIGUSR1 将子 pid 发送给父亲

c - Gwan 包含脚本

c - 用星号填充形状

C - 字符数组似乎可以复制,但仅限于循环范围内

memory-leaks - Ada任务声明导致内存泄漏

c++ - 在 Valgrind 中运行我的程序时如何调试?

c - 丑陋的 C 结构分配的现代 C++ 模式

c - 尝试释放 int 指针数组时出现 valgrind 错误。不知道为什么

linux - 能否将信号从自身进程推送到自身进程,然后作为 EPOLL 上的事件处理?

c++ - 无法使用 gcc 构建 sigqueue 示例,但 g++ 可以吗?