Valgrind errors in context in C

时间:2018-08-19 06:19:22

标签: c valgrind

I'm getting this error but cant find the cause, it's a project and i can't really show the source code here, but I allocate memory like this:

if(!data_counter)
    lab=(ptr)malloc(sizeof(item));
else
    lab=(ptr)realloc(lab,sizeof(item)*(DC+1));

I keep getting this log in Valgrind, even though my code compiles and runs perfectly.
I have feeling that i reallocate the memory wrong. Also the item in sizeof(item) is a struct with 4 fields

==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)  

any help will be appreciated

1 个答案:

答案 0 :(得分:1)

如果您指的是Conditional jump or move depends on uninitialized value(s)错误,则表示您的条件中包含未初始化的值。

这可能是whileforifswitch语句中的条件。从Valgrind回溯中,您可以看出checkLabelupdate_labl_adrr中有一些流控制语句,但是由于我们看不到该代码,因此很难说出其他任何内容。

在使用递归结构(即链表,树等)时,一个常见的错误是未将next / child指针初始化为NULL。这通常会导致您发布的错误。但是,这是一个完整的猜测,因为我们再次对您的代码一无所知。
至少,不知道checkLabelupdate_labl_addr

中写的内容,就无法提供进一步的帮助。