RDK Resources
[*RDK Preferred*]
Code Management Facility
RDK Forums
[RDK Conferences]
RDK Support
Archives
Papers & Presentations Archive
Valgrind:-
It shows memory leaks, deallocation errors in the program
Installation:-
By adding the below tool, we can install valgrind in RPI-target
IMAGE_INSTALL_APPEND+=" valgrind" in the <image_recipe.bbappend>
Command to check in GW:-
valgrind --tool=memcheck --leak-check=full --show-reachable=yes --num-callers=20 --track-fds=yes /usr/bin/<component>
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
Input code: In ssp_main.c of CcspPandM
+int* bar()
+{ int *p12;
+ p12 = (int*)malloc(1024*1024* sizeof( int));
+ return p12;
+}
int main(int argc, char* argv[])
{ int s, svalue = -1;
errno_t rc = -1;
int ret = 0;
+ bar(); //536 line in the valgrind output[by 0x40354B: main (ssp_main.c:536)]
}
Command : root@RaspberryPi-Gateway:/usr/bin# valgrind --leak-check=full ./CcspPandMSsp
Output of valgrind:
==7627== 4,194,304 bytes in 1 blocks are possibly lost in loss record 96 of 97
==7627== at 0x48461E0: malloc (vg_replace_malloc.c:309)
==7627== by 0x40354B: main (ssp_main.c:536)
==7627==
==7627== 4,194,304 bytes in 1 blocks are possibly lost in loss record 97 of 97
==7627== at 0x48461E0: malloc (vg_replace_malloc.c:309)
==7627== by 0x4035A7: main (ssp_main.c:567)
==7627==
==7627== LEAK SUMMARY:
==7627== definitely lost: 683 bytes in 1 blocks
==7627== indirectly lost: 0 bytes in 0 blocks
==7627== possibly lost: 8,388,608 bytes in 2 blocks
==7627== still reachable: 68,647 bytes in 1,341 blocks
==7627== 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==
==7627== For lists of detected and suppressed errors, rerun with: -s
==7627== ERROR SUMMARY: 3 errors from 3 contexts (suppressed: 0 from 0)