【问题标题】:memory leak when creating local opencv mat object创建本地 opencv mat 对象时发生内存泄漏
【发布时间】:2023-03-10 01:50:01
【问题描述】:

我有一个函数,我做一个垫子操作。

  void my_func()

   {

     vector<Point> my_vect=another_func();

     Mat my_array((int)my_vect.size(),1,CV_8UC1); //This line is reported as leakage

     for(int i=0;i<my_vect.size();i++)

     my_array.at<uchar>(i,1)=Other_image.at<uchar>(my_vect[i]); 

   }

【问题讨论】:

  • 而 another_func() 是...?
  • @lundin 函数在其上推送数据
  • 如果你有内存泄漏,使用 valgrind 来分析泄漏。

标签: c++ opencv memory-management memory-leaks


【解决方案1】:

不知道泄漏,但至少还有一个缓冲区溢出。

Mat my_array( 17, 1, CV_8UC1 ); // 17 rows, 1 col
for(int i=0; i<17; i++)
     // should be (i,0) below, (i,1) is already out of bounds
     my_array.at<uchar>(i,1) = Other_image.at<uchar>(my_vect[i]); // <-- this looks broken, too

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-01-17
    • 1970-01-01
    • 2018-04-01
    • 1970-01-01
    • 2015-02-12
    • 1970-01-01
    • 1970-01-01
    • 2015-11-06
    相关资源
    最近更新 更多