我看到一个奇怪的问题。示例代码包含在下面
当这段代码用 valgrind 运行时,它抱怨 popen 分配的内存仍然可以访问。我应该担心这个警告吗?如果是,有什么可能的解决方案?
Func1()
FILE *fp = NULL;
int fd = 0;
fp = popen(g_cmd, "r");
fd = fileno(fp); // store fd for later processing.
...
Func2(fd)
FILE *popen_fp = NULL;
popen_fp = fdopen(fd, "r"); // Convert fd to File pointer.
if (popen_fp) pclose(popen_fp);
==11748== 256 bytes in 1 blocks are still reachable in loss record 1 of 1
==11748== at 0x4C29F73: malloc
==11748== by 0x5542627: popen@@GLIBC_2.2.5
LEAK SUMMARY:
==11748== definitely lost: 0 bytes in 0 blocks
==11748== indirectly lost: 0 bytes in 0 blocks
==11748== possibly lost: 0 bytes in 0 blocks
==11748== still reachable: 256 bytes in 1 blocks