linux - 尝试使用开放式 CV 和 SDL 追踪内存泄漏

标签 linux opencv sdl cups

下面的程序主循环是我无法找到内存泄漏的地方。我运行 Top,每次循环拍照并打印时,我都会失去内存,即使退出也无法恢复。我运行了 valgrind,一些结果在底部。该程序运行良好,直到内存不足。我似乎有 cups 和 opencv 的泄漏,泄漏不是几百个字节,这很重要 - 我感谢任何帮助

Ubuntu 11.04 opencv 2.3.1

void DrawImage(SDL_Surface *srcimg, int sx, int sy, int sw, int sh, SDL_Surface *dstimg, int dx, int dy, int alpha) {
  if ((!srcimg) || (alpha == 0)) return; //If theres no image, or its 100% transparent.
  SDL_Rect src, dst;
  src.x = sx;  src.y = sy;  src.w = sw;  src.h = sh;
  dst.x = dx;  dst.y = dy;  dst.w = src.w;  dst.h = src.h;
  SDL_BlitSurface(srcimg, &src, dstimg, &dst);
}


// ************************ Start of Main Loop ************************

while(Leave == 0)   
{

if(Start != 0)
{
    atr = IMG_Load("pic1.jpg");
    DrawImage(atr, 0,0,DSP_WIDTH,DSP_HEIGHT,screen, 0, 0, 255);
    SDL_Flip(screen);

    CvCapture *camera = cvCreateCameraCapture(-1); 
    IplImage *frame2; 

    SDL_Surface* surface = NULL;

    cvSetCaptureProperty(camera, CV_CAP_PROP_FRAME_HEIGHT, IMG_HEIGHT);
    cvSetCaptureProperty(camera, CV_CAP_PROP_FRAME_WIDTH, IMG_WIDTH);

    surface = IMG_Load("background.jpg");

    Seconds = 15;
    while(Seconds !=0)
    {
       frame2 = cvQueryFrame(camera);
       if(!frame2)continue; //Couldn't get an image, try again next time.

       SDL_Surface* surface2 = NULL;

       surface2 = SDL_CreateRGBSurfaceFrom((void*)frame2->imageData,
              frame2->width,
              frame2->height,
              frame2->depth*frame2->nChannels,
              frame2->widthStep,
              0xff0000, 0x00ff00, 0x0000ff, 0);

      SDL_BlitSurface(surface2, NULL, surface, &offsetpic);

      SDL_FreeSurface(surface2);

      DrawImage(surface, 0,0,DSP_WIDTH,DSP_HEIGHT,screen, 0, 0, 255);
      SDL_Flip(screen);

    }

  if(!cvSaveImage("lastprint.jpg",frame2,0)) printf("Could not save: lastprint.jpg");

  cvReleaseImage(&frame2);
  cvReleaseCapture(&camera); //Release the camera capture structure.
  SDL_FreeSurface(surface);

  cupsPrintFile(dest->name, "lastprint.jpg", "JOB1", dest->num_options, dest->options);
  if(Start !=0) Start--;                // Dec Start

//      atr = IMG_Load("pic1.jpg");
  DrawImage(atr, 0,0,DSP_WIDTH,DSP_HEIGHT,screen, 0, 0, 255);
  SDL_Flip(screen);

  }
}

很多直接在下面的vvvvv

32,780 字节在 1 个 block 中仍然可以在丢失记录 180 of 182 中访问

在 0x4026864:malloc (vg_replace_malloc.c:236)

来自 0x4365BA7:??? (在/usr/lib/libcups.so.2 中)

通过 0x436731E:ippReadIO(在/usr/lib/libcups.so.2 中)

通过 0x436785C:ippReadIO(在/usr/lib/libcups.so.2 中)

通过 0x436785C:ippReadIO(在/usr/lib/libcups.so.2 中)

通过 0x4367E85:ippRead(在/usr/lib/libcups.so.2 中)

通过 0x437A173:cupsGetResponse(在/usr/lib/libcups.so.2 中)

通过 0x437A501:cupsDoIORequest(在/usr/lib/libcups.so.2 中)

通过 0x437A6FA:cupsDoRequest(在/usr/lib/libcups.so.2 中)

来自 0x4358386:??? (在/usr/lib/libcups.so.2 中)

通过 0x4359D52:cupsGetDests2(在/usr/lib/libcups.so.2 中)

通过 0x435A1B4:cupsGetDests(在/usr/lib/libcups.so.2 中)

1,440,020 bytes in 1 blocks is possibly lost in loss record 181 of 182

在 0x4026864:malloc (vg_replace_malloc.c:236)

通过 0x415D0EB:cv::fastMalloc(unsigned int)(在/usr/local/lib/libopencv_core.so.2.3.1 中)

by 0x4A5DE36: (below main) (libc-start.c:226) ---DrawImage 是 main 下面唯一的东西

67,108,864 bytes 4个block中的丢失记录182 of 182中可能丢失

在 0x4026864:malloc (vg_replace_malloc.c:236)

通过 0x473C057:_capture_V4L2(CvCaptureCAM_V4L*, char*)(在/usr/local/lib/libopencv_highgui.so.2.3.1 中)

最佳答案

嗯,至少你永远不会在 atr 上调用 SDL_FreeSurface()

关于linux - 尝试使用开放式 CV 和 SDL 追踪内存泄漏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7600526/

相关文章:

linux - 用于验证 SVN 项目有效性的 Bash 脚本

java - OpenCV(java)魔方识别调色

c++ - SDL 卡住但继续运行

c++ - 将代码从 C 转换为 C++

linux - Cassandra - 删除旧版本的表和备份数据库

python - skimage转换为灰度,生成黑色图像

c++ - SDL:全屏半透明背景

c++ - C++ 中非常特殊的链接器错误

linux - 是否可以将 Kinect 连接到 Unity3D 并编译使其在 Jetson TK1 上运行?

java - RGB值,有没有255的值,255是什么意思?