Valgrind OpenCV

Valgrind OpenCV

这是我的测试程序:

#include "opencv2/videoio.hpp"

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

我运行这个程序是这样的:

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

以便将整个输出保存在 valgrind_output 文件中。

valgrind_output的内容可以查看here

但是,如果 link 将来死了,这是总结:

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

我想将 "possibly lost" 字节减少到 0。这可能吗?或者在使用 OpenCV 时我总是会有一些 "possibly lost" 字节吗?

OpenCV 附带 suppression 文件(扩展名为 .supp)用于 valgrind,可用于隐藏有关已分配资源的消息(通常在程序执行的早期)将一直分配到程序结束并且 OS 必须清理混乱。

抑制文件位于 /usr/share/OpenCV(在我的系统上):

示例:

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

OpenCV 项目 运行 valgrind 中使用这些对我帮助很大。