C 中上下文中的 Valgrind 错误
Valgrind errors in context in C
我遇到了这个错误,但找不到原因,这是一个项目,我不能在这里真正显示源代码,但我是这样分配内存的:
if(!data_counter)
lab=(ptr)malloc(sizeof(item));
else
lab=(ptr)realloc(lab,sizeof(item)*(DC+1));
我一直在 Valgrind 中获取此日志,即使我的代码可以完美编译和运行。
我觉得我重新分配了内存错误。
sizeof(item) 中的项目也是一个有 4 个字段的结构
==18449==
==18449== HEAP SUMMARY:
==18449== in use at exit: 352 bytes in 1 blocks
==18449== total heap usage: 15 allocs, 14 frees, 4,416 bytes allocated
==18449==
==18449== Searching for pointers to 1 not-freed blocks
==18449== Checked 69,180 bytes
==18449==
==18449== LEAK SUMMARY:
==18449== definitely lost: 0 bytes in 0 blocks
==18449== indirectly lost: 0 bytes in 0 blocks
==18449== possibly lost: 0 bytes in 0 blocks
==18449== still reachable: 352 bytes in 1 blocks
==18449== suppressed: 0 bytes in 0 blocks
==18449== Reachable blocks (those to which a pointer was found) are not shown.
==18449== To see them, rerun with: --leak-check=full --show-reachable=yes
==18449==
==18449== Use --track-origins=yes to see where uninitialised values come from
==18449== ERROR SUMMARY: 4 errors from 3 contexts (suppressed: 0 from 0)
==18449==
==18449== 1 errors in context 1 of 3:
==18449== Conditional jump or move depends on uninitialised value(s)
==18449== at 0x804B960: checkLabel (12.c:797)
==18449== by 0x8048B55: line_parser (12.c:132)
==18449== by 0x8048914: file_parser (12.c:108)
==18449== by 0x804C5CE: main (12.c:995)
==18449==
==18449==
==18449== 1 errors in context 2 of 3:
==18449== Conditional jump or move depends on uninitialised value(s)
==18449== at 0x804BC24: checkLabel (12.c:836)
==18449== by 0x8048B55: line_parser (12.c:132)
==18449== by 0x8048914: file_parser (12.c:108)
==18449== by 0x804C5CE: main (12.c:995)
==18449==
==18449==
==18449== 2 errors in context 3 of 3:
==18449== Conditional jump or move depends on uninitialised value(s)
==18449== at 0x804BE61: update_labl_adrr (12.c:883)
==18449== by 0x804C720: main (12.c:1014)
==18449==
==18449== ERROR SUMMARY: 4 errors from 3 contexts (suppressed: 0 from 0)
任何帮助将不胜感激
如果您指的是 Conditional jump or move depends on uninitialized value(s)
错误,这意味着您的条件包含未初始化的值。
这可以是 while
、for
、if
或 switch
语句中的条件。从 Valgrind 回溯中,您可以看出 checkLabel
和 update_labl_adrr
中有一些流程控制语句,但由于我们看不到该代码,因此很难说出其他任何内容。
使用递归结构(即链表、树等)时的一个常见错误是没有将 next
/child
指针初始化为 NULL。这通常会导致您发布错误。但是,这完全是猜测,因为我们对您的代码一无所知。
至少,如果不了解 checkLabel
和 update_labl_addr
中的内容,就无法进一步提供帮助
我遇到了这个错误,但找不到原因,这是一个项目,我不能在这里真正显示源代码,但我是这样分配内存的:
if(!data_counter)
lab=(ptr)malloc(sizeof(item));
else
lab=(ptr)realloc(lab,sizeof(item)*(DC+1));
我一直在 Valgrind 中获取此日志,即使我的代码可以完美编译和运行。
我觉得我重新分配了内存错误。
sizeof(item) 中的项目也是一个有 4 个字段的结构
==18449==
==18449== HEAP SUMMARY:
==18449== in use at exit: 352 bytes in 1 blocks
==18449== total heap usage: 15 allocs, 14 frees, 4,416 bytes allocated
==18449==
==18449== Searching for pointers to 1 not-freed blocks
==18449== Checked 69,180 bytes
==18449==
==18449== LEAK SUMMARY:
==18449== definitely lost: 0 bytes in 0 blocks
==18449== indirectly lost: 0 bytes in 0 blocks
==18449== possibly lost: 0 bytes in 0 blocks
==18449== still reachable: 352 bytes in 1 blocks
==18449== suppressed: 0 bytes in 0 blocks
==18449== Reachable blocks (those to which a pointer was found) are not shown.
==18449== To see them, rerun with: --leak-check=full --show-reachable=yes
==18449==
==18449== Use --track-origins=yes to see where uninitialised values come from
==18449== ERROR SUMMARY: 4 errors from 3 contexts (suppressed: 0 from 0)
==18449==
==18449== 1 errors in context 1 of 3:
==18449== Conditional jump or move depends on uninitialised value(s)
==18449== at 0x804B960: checkLabel (12.c:797)
==18449== by 0x8048B55: line_parser (12.c:132)
==18449== by 0x8048914: file_parser (12.c:108)
==18449== by 0x804C5CE: main (12.c:995)
==18449==
==18449==
==18449== 1 errors in context 2 of 3:
==18449== Conditional jump or move depends on uninitialised value(s)
==18449== at 0x804BC24: checkLabel (12.c:836)
==18449== by 0x8048B55: line_parser (12.c:132)
==18449== by 0x8048914: file_parser (12.c:108)
==18449== by 0x804C5CE: main (12.c:995)
==18449==
==18449==
==18449== 2 errors in context 3 of 3:
==18449== Conditional jump or move depends on uninitialised value(s)
==18449== at 0x804BE61: update_labl_adrr (12.c:883)
==18449== by 0x804C720: main (12.c:1014)
==18449==
==18449== ERROR SUMMARY: 4 errors from 3 contexts (suppressed: 0 from 0)
任何帮助将不胜感激
如果您指的是 Conditional jump or move depends on uninitialized value(s)
错误,这意味着您的条件包含未初始化的值。
这可以是 while
、for
、if
或 switch
语句中的条件。从 Valgrind 回溯中,您可以看出 checkLabel
和 update_labl_adrr
中有一些流程控制语句,但由于我们看不到该代码,因此很难说出其他任何内容。
使用递归结构(即链表、树等)时的一个常见错误是没有将 next
/child
指针初始化为 NULL。这通常会导致您发布错误。但是,这完全是猜测,因为我们对您的代码一无所知。
至少,如果不了解 checkLabel
和 update_labl_addr