English 中文(简体)
三、MacOS X的 p所造成的严重错误
原标题:Valgrind errors caused by pclose() on Mac OS X

I m 试图pclose()的管道以前开着popen(>)。 错误出现在MacOS X,但并未出现在Ltino。 考虑以下例子:

#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
", 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

转载于<条码>-轨道-地根> ,衰期中显示,问题的根源可能出现在<条码>上。 4.2.1和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)
最佳回答

该系统图书馆通常通过未经开户进入系统电话。 有条件的跳跃取决于未获得的初始价值不太常见,但这种情况确实发生(在我的短链氯化石蜡建筑中的gli2.X.supp含有8个抑制,用于平衡)。

既然你无法对这些错误做任何事,那么你就应当只是加以压制。 See -gen-suppressions in Valgrind docs.

问题回答

所报告的问题似乎是系统图书馆的内部问题,而不是你的代码。

我也没有使用MacOS X 10.6.8、Valgrind 3.6.0以及(Apple s)《海合会》4.2.1或(my)4.6.0的错误。 我确实收到了你的法典(4.6.0所示)的汇编警告——实际上,我指挥了指挥,而且档案中载有所有这些论点:<代码>-Wxxx:

$ gcc -g -std=c99 -Wall -Wextra -Wmissing-prototypes -Wstrict-prototypes -Wold-style-definition     vg.c -o vg
vg.c:4:5: warning: function declaration isn’t a prototype [-Wstrict-prototypes]
vg.c: In function ‘main’:
vg.c:4:5: warning: old-style function definition [-Wold-style-definition]
$ valgrind vg
==40593== Memcheck, a memory error detector
==40593== Copyright (C) 2002-2010, and GNU GPL d, by Julian Seward et al.
==40593== Using Valgrind-3.6.0 and LibVEX; rerun with -h for copyright info
==40593== Command: vg
==40593== 
vg
vg.c
vg.dSYM
==40593== 
==40593== HEAP SUMMARY:
==40593==     in use at exit: 4,184 bytes in 2 blocks
==40593==   total heap usage: 6 allocs, 4 frees, 26,848 bytes allocated
==40593== 
==40593== LEAK SUMMARY:
==40593==    definitely lost: 0 bytes in 0 blocks
==40593==    indirectly lost: 0 bytes in 0 blocks
==40593==      possibly lost: 0 bytes in 0 blocks
==40593==    still reachable: 4,184 bytes in 2 blocks
==40593==         suppressed: 0 bytes in 0 blocks
==40593== Rerun with --leak-check=full to see details of leaked memory
==40593== 
==40593== For counts of detected and suppressed errors, rerun with: -v
==40593== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
$ cc --version
i686-apple-darwin10-llvm-gcc-4.2 (GCC) 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2335.9)
Copyright (C) 2007 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

$ gcc --version
gcc (GCC) 4.6.0
Copyright (C) 2011 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

$ valgrind --version
valgrind-3.6.0
Localhost JL: uname -a
Darwin localhost 10.8.0 Darwin Kernel Version 10.8.0: Tue Jun  7 16:33:36 PDT 2011; root:xnu-1504.15.3~1/RELEASE_I386 i386
$ otool -L /usr/lib/libSystem.B.dylib
/usr/lib/libSystem.B.dylib:
    /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 125.2.11)
    /usr/lib/system/libmathCommon.A.dylib (compatibility version 1.0.0, current version 315.0.0)

当使用<代码>-v-gen-suppressions=yes时,valgrind报告更多信息,但仍未发现被抑制的错误。

这一错误在最新的Valgrind SVN来源中解决。 瓦利德的一些内部博客已经解决,已知的 Apple果系统图书馆泡沫被粉碎。

Note this is running on OS X 10.10.4

$ ./vg-in-place ../../test
==55558== Memcheck, a memory error detector
==55558== Copyright (C) 2002-2013, and GNU GPL d, by Julian Seward et al.
==55558== Using Valgrind-3.11.0.SVN and LibVEX; rerun with -h for copyright info
==55558== Command: ../../test
==55558== 
--55558-- ../../test:
--55558-- dSYM directory is missing; consider using --dsymutil=yes
AUTHORS
COPYING
COPYING.DOCS
Makefile
...
vg-in-place
xfree-3.supp
xfree-4.supp
==55558== 
==55558== HEAP SUMMARY:
==55558==     in use at exit: 39,331 bytes in 419 blocks
==55558==   total heap usage: 523 allocs, 104 frees, 68,971 bytes allocated
==55558== 
==55558== LEAK SUMMARY:
==55558==    definitely lost: 0 bytes in 0 blocks
==55558==    indirectly lost: 0 bytes in 0 blocks
==55558==      possibly lost: 0 bytes in 0 blocks
==55558==    still reachable: 0 bytes in 0 blocks
==55558==         suppressed: 39,331 bytes in 419 blocks
==55558== 
==55558== For counts of detected and suppressed errors, rerun with: -v
==55558== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
$ ./vg-in-place --version
valgrind-3.11.0.SVN




相关问题
Fastest method for running a binary search on a file in C?

For example, let s say I want to find a particular word or number in a file. The contents are in sorted order (obviously). Since I want to run a binary search on the file, it seems like a real waste ...

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

Tips for debugging a made-for-linux application on windows?

I m trying to find the source of a bug I have found in an open-source application. I have managed to get a build up and running on my Windows machine, but I m having trouble finding the spot in the ...

Trying to split by two delimiters and it doesn t work - C

I wrote below code to readin line by line from stdin ex. city=Boston;city=New York;city=Chicago and then split each line by ; delimiter and print each record. Then in yet another loop I try to ...

Good, free, easy-to-use C graphics libraries? [closed]

I was wondering if there were any good free graphics libraries for C that are easy to use? It s for plotting 2d and 3d graphs and then saving to a file. It s on a Linux system and there s no gnuplot ...

Encoding, decoding an integer to a char array

Please note that this is not homework and i did search before starting this new thread. I got Store an int in a char array? I was looking for an answer but didn t get any satisfactory answer in the ...

热门标签