Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Valgrind OpenCV

Here is my test program:

#include "opencv2/videoio.hpp"

int main(int argc, char** argv) {
    cv::VideoCapture videoCapture(argv[1]);
    cv::Mat frame;
    videoCapture.read(frame);
    return 0;
}

I run this program like this:

valgrind --leak-check=yes ./GyroRecord ./walks6/w63/39840012.avi > valgrind_output 2>&1

So that the entire output is saved in the valgrind_output file.

The contents of valgrind_output can be checked here.

But, if the link dies in the future, this is the summary:

==9677== LEAK SUMMARY:
==9677==    definitely lost: 0 bytes in 0 blocks
==9677==    indirectly lost: 0 bytes in 0 blocks
==9677==      possibly lost: 1,352 bytes in 18 blocks
==9677==    still reachable: 166,408 bytes in 1,296 blocks
==9677==                       of which reachable via heuristic:
==9677==                         newarray           : 1,536 bytes in 16 blocks
==9677==         suppressed: 0 bytes in 0 blocks
==9677== Reachable blocks (those to which a pointer was found) are not shown.
==9677== To see them, rerun with: --leak-check=full --show-leak-kinds=all
==9677== 
==9677== For counts of detected and suppressed errors, rerun with: -v
==9677== ERROR SUMMARY: 18 errors from 18 contexts (suppressed: 0 from 0)

I would like to reduce "possibly lost" bytes to 0. Is that possible? Or will I always have some "possibly lost" bytes when using OpenCV?

like image 345
ancajic Avatar asked Oct 19 '25 12:10

ancajic


1 Answers

OpenCV comes with suppression files (with the extension .supp) for valgrind that can be used to hide messages about resources allocated (often early in he program's execution) that will be kept allocated until the program dies and the OS has to clean up the mess.

The suppression files are placed in /usr/share/OpenCV (on my system):

Example:

valgrind --leak-check=yes --suppressions=/usr/share/OpenCV/valgrind.supp --suppressions=/usr/share/OpenCV/valgrind_3rdparty.supp ./GyroRecord ./walks6/w63/39840012.avi

Using these helped me a lot when running valgrind on an OpenCV project.

like image 174
Ted Lyngmo Avatar answered Oct 22 '25 02:10

Ted Lyngmo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!