我有一个包含记录的文件,想通过在项目内部调用sort
来整理它们。运行该程序时一切似乎都很好,但是尝试用leaks
检查valgrind
时,我遇到了很多错误。这是我用来执行的代码:
execlp("sort", "-g", "results", (char*) NULL);
results
是我要整理的文件。
还有错误。
==27691==
==27691== HEAP SUMMARY:
==27691== in use at exit: 1,352 bytes in 17 blocks
==27691== total heap usage: 66 allocs, 49 frees, 44,055 bytes allocated
==27691==
==27691== 16 bytes in 1 blocks are definitely lost in loss record 1 of 6
==27691== at 0x4C2DB8F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==27691== by 0x4110C8: ??? (in /usr/bin/sort)
==27691== by 0x402FFD: ??? (in /usr/bin/sort)
==27691== by 0x507782F: (below main) (libc-start.c:291)
==27691==
==27691== 64 bytes in 1 blocks are indirectly lost in loss record 2 of 6
==27691== at 0x4C2DB8F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==27691== by 0x4110C8: ??? (in /usr/bin/sort)
==27691== by 0x40D33C: ??? (in /usr/bin/sort)
==27691== by 0x4046A2: ??? (in /usr/bin/sort)
==27691== by 0x507782F: (below main) (libc-start.c:291)
==27691==
==27691== 88 bytes in 12 blocks are still reachable in loss record 3 of 6
==27691== at 0x4C2DB8F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==27691== by 0x4110C8: ??? (in /usr/bin/sort)
==27691== by 0x402D66: ??? (in /usr/bin/sort)
==27691== by 0x507782F: (below main) (libc-start.c:291)
==27691==
==27691== 128 bytes in 1 blocks are still reachable in loss record 4 of 6
==27691== at 0x4C2DB8F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==27691== by 0x4C2FDEF: realloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==27691== by 0x411125: ??? (in /usr/bin/sort)
==27691== by 0x405D89: ??? (in /usr/bin/sort)
==27691== by 0x4043C0: ??? (in /usr/bin/sort)
==27691== by 0x507782F: (below main) (libc-start.c:291)
==27691==
==27691== 1,024 bytes in 1 blocks are indirectly lost in loss record 5 of 6
==27691== at 0x4C2DB8F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==27691== by 0x4110C8: ??? (in /usr/bin/sort)
==27691== by 0x4046D4: ??? (in /usr/bin/sort)
==27691== by 0x507782F: (below main) (libc-start.c:291)
==27691==
==27691== 1,120 (32 direct, 1,088 indirect) bytes in 1 blocks are definitely lost in loss record 6 of 6
==27691== at 0x4C2DB8F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==27691== by 0x4110C8: ??? (in /usr/bin/sort)
==27691== by 0x40D313: ??? (in /usr/bin/sort)
==27691== by 0x4046A2: ??? (in /usr/bin/sort)
==27691== by 0x507782F: (below main) (libc-start.c:291)
==27691==
==27691== LEAK SUMMARY:
==27691== definitely lost: 48 bytes in 2 blocks
==27691== indirectly lost: 1,088 bytes in 2 blocks
==27691== possibly lost: 0 bytes in 0 blocks
==27691== still reachable: 216 bytes in 13 blocks
==27691== suppressed: 0 bytes in 0 blocks
==27691==
==27691== For counts of detected and suppressed errors, rerun with: -v
==27691== ERROR SUMMARY: 2 errors from 2 contexts (suppressed: 0 from 0)
我做错什么了吗?我没有分配任何指针,并且似乎没有错误,因为它们没有出现在我的项目中。