Valgrind:
...
It shows memory leaks, deallocation errors in the program
Installation:
...
By adding the below tool, we can install valgrind in RPI-target
Code Block |
---|
|
IMAGE_INSTALL_APPEND += " valgrind" in the |
...
...
Code Block |
---|
language | c# |
---|
theme | DJango |
---|
title | Command |
---|
|
...
...
|
valgrind --tool=memcheck --leak-check=full --show-reachable=yes --num-callers=20 --track-fds=yes /usr/bin/ |
...
Defining the options:
...
|
--tool=memcheck: "To the check the memory" --leak-check=full: "each individual leak will be shown in detail" --show-reachable=yes: "When enabled, the leak detector also shows "reachable" and "indirectly lost" blocks" --num-callers=20: "Specifies the maximum number of entries shown in stack traces that identify program locations" --track-fds=yes: "When enabled, Valgrind will print out a list of open file descriptors on exit." /usr/bin/<component>: "Component's binary path" |
...
Use
...
case:
Sample output of valgrind to reproduce leak for created memory leak
Code Block |
---|
|
Input code: In ssp_main.c of CcspPandM |
...
...
...
+ p12 = (int*)malloc(1024*1024* sizeof( int)); |
...
...
...
...
int main(int argc, char* argv[]) |
...
...
...
...
+ bar(); //536 line in the valgrind output[by 0x40354B: main (ssp_main.c:536)] |
...
...
...
root@RaspberryPi-Gateway:/usr/ |
...
bin# valgrind --leak-check=full ./CcspPandMSsp |
...
...
...
==7627== 4,194,304 bytes in 1 blocks are possibly lost in loss record 96 of 97 |
...
...
...
at 0x48461E0: malloc (vg_replace_malloc.c:309) |
...
...
by 0x40354B: main (ssp_main.c:536) |
...
...
==7627== 4,194,304 bytes in 1 blocks are possibly lost in loss record 97 of 97 |
...
...
at 0x48461E0: malloc (vg_replace_malloc.c:309) |
...
...
by 0x4035A7: main (ssp_main.c:567) |
...
...
...
...
definitely lost: 683 bytes in 1 blocks |
...
...
...
indirectly lost: 0 bytes in 0 blocks |
...
...
possibly lost: 8,388,608 bytes in 2 blocks |
...
...
...
still reachable: 68,647 bytes in 1,341 blocks |
...
...
suppressed: 0 bytes in 0 blocks |
...
==7627== Reachable blocks (those to which a pointer was found) are not shown. |
...
==7627== To see them, rerun with: --leak-check=full --show-leak-kinds=all |
...
...
==7627== For lists of detected and suppressed errors, rerun with: -s |
...
==7627== ERROR SUMMARY: 3 errors from 3 contexts (suppressed: 0 from 0) |