造成在Mac OS X pclose函数()Valgrind的错误 [英] Valgrind errors caused by pclose() on Mac OS X
问题描述
我试图 pclose函数时,得到的valgrind错误()
管道$ P $与的popen()pviously打开
。出现在Mac OS X中的错误,但不能在Linux上。请看下面的例子:
的#include<&stdlib.h中GT;
#包括LT&;&stdio.h中GT;诠释主(){
FILE * FP;
焦炭BUF [4096]; 如果(!(FP =的popen(LS,R)))
出口(-1); 而(的fscanf(FP,%S,BUF)== 1)
的printf(%S \\ n,BUF); pclose函数(FP); 返回0;
}
我得到的是Mac(OS X 10.6.7,Valgrind的版本3.6.0)以下Valgrind的错误,除非我删除函数,pclose()
电话:
== == 21455条件跳转或移动依赖于未初始化值(S)
== == 21455在0xB1992:pclose函数(在/usr/lib/libSystem.B.dylib)
== == 21455通过0x1F16:主(以./a.out)
== == 21455
== == 21455参数系统调用wait4(PID)包含未初始化的字节
== == 21455在0x504FA:wait4(以/usr/lib/libSystem.B.dylib)
== == 21455通过0x1F16:主(以./a.out)
不过,我没有得到任何错误Linux系统与Valgrind的版本3.5.0上。
这是什么可能会导致Mac上的错误任何想法?
更新
打开 - 轨道起源
在Valgrind的显示问题的起源可能是在的popen()
调用。得到了同样的事情用gcc 4.2.1和4.5.3。
== == 4425条件跳转或移动依赖于未初始化值(S)
== == 4425在0xB1992:pclose函数(在/usr/lib/libSystem.B.dylib)
== == 4425通过0x1F18:主(以./a.out)
== == 4425值未初始化是由堆栈分配创建
== == 4425在0xB14C5:popen方法$ UNIX2003(以/usr/lib/libSystem.B.dylib)
== == 4425
== == 4425参数系统调用wait4(PID)包含未初始化的字节
== == 4425在0x504FA:wait4(以/usr/lib/libSystem.B.dylib)
== == 4425通过0x1F18:主(以./a.out)
== == 4425值未初始化是由堆栈分配创建
== == 4425在0xB14C5:popen方法$ UNIX2003(以/usr/lib/libSystem.B.dylib)
这是很常见的系统库未初始化的字节传递给系统调用。这是不太常见的条件跳转依赖于未初始化的价值,但它确实发生(的glibc-2.X.supp在我的Linux版本包含8燮pressions此glibc中)。
由于没有什么可以做的这些错误,无论如何,你应该只燮preSS他们。参见 - 根燮pressions
在Valgrind的文档
I'm getting valgrind errors when attempting to pclose()
a pipe previously open with popen()
. The errors occur on Mac OS X, but not on Linux. Consider the following example:
#include <stdlib.h>
#include <stdio.h>
int main() {
FILE *fp;
char buf[4096];
if (!(fp = popen("ls", "r")))
exit(-1);
while (fscanf(fp, "%s", buf) == 1)
printf("%s\n", buf);
pclose(fp);
return 0;
}
I get the following valgrind errors on a Mac (OS X 10.6.7, valgrind version 3.6.0), except if I remove the pclose()
call:
==21455== Conditional jump or move depends on uninitialised value(s)
==21455== at 0xB1992: pclose (in /usr/lib/libSystem.B.dylib)
==21455== by 0x1F16: main (in ./a.out)
==21455==
==21455== Syscall param wait4(pid) contains uninitialised byte(s)
==21455== at 0x504FA: wait4 (in /usr/lib/libSystem.B.dylib)
==21455== by 0x1F16: main (in ./a.out)
However, I don't get any errors on a Linux system with valgrind version 3.5.0.
Any ideas on what could be causing the errors on the Mac?
Update
Turning on --track-origins
in valgrind shows that the origin of the problem might be in the popen()
call. Got the same thing with gcc 4.2.1 and 4.5.3.
==4425== Conditional jump or move depends on uninitialised value(s)
==4425== at 0xB1992: pclose (in /usr/lib/libSystem.B.dylib)
==4425== by 0x1F18: main (in ./a.out)
==4425== Uninitialised value was created by a stack allocation
==4425== at 0xB14C5: popen$UNIX2003 (in /usr/lib/libSystem.B.dylib)
==4425==
==4425== Syscall param wait4(pid) contains uninitialised byte(s)
==4425== at 0x504FA: wait4 (in /usr/lib/libSystem.B.dylib)
==4425== by 0x1F18: main (in ./a.out)
==4425== Uninitialised value was created by a stack allocation
==4425== at 0xB14C5: popen$UNIX2003 (in /usr/lib/libSystem.B.dylib)
It is quite common for system libraries to pass uninitialized bytes to system calls. It is less common for conditional jump to depend on uninitialized value, but it does happen (glibc-2.X.supp in my Linux build contains 8 suppressions for this in glibc).
Since there is nothing you can do about these errors anyway, you should just suppress them. See --gen-suppressions
in Valgrind docs.
这篇关于造成在Mac OS X pclose函数()Valgrind的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!