开发者

trying to track down a Memory Leak using open CV and SDL

开发者 https://www.devze.com 2023-04-09 15:26 出处:网络
The program main loop below is where I am having troubles finding a memory leak.I run Top and every time I loop through taking a picture and printing it, I lose memory that is never recovered even upo

The program main loop below is where I am having troubles finding a memory leak. I run Top and every time I loop through taking a picture and printing it, I lose memory that is never recovered even upon exit. I have run valgrind and some results are at the bottom. The progam runs fine until it runs out of memory. I seem to have leaks with cups and opencv and the leak is not a couple hundred bytes it is significant - I appreciate any help

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

  }
}

Many of the one directly below here vvvvv

32,780 bytes in 1 blocks are still reachable in loss record 180 of 182

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

by 0x4365BA7: ??? (in /usr/lib/libcups.so.2)

by 0x436731E: ippReadIO (in /usr/lib/libcups.so.2)

by 0x436785C: ippReadIO (in /usr/lib/libcups.so.2)

by 0x436785C: ippReadIO (in /usr/lib/libcups.so.2)

by 0x4367E85: ippRead (in /usr/lib/libcups.so.2)

by 0x437A173: cupsGetResponse (in /usr/lib/libcups.so.2)

by 0x437A501: cupsDoIORequest (in /usr/lib/libcups.so.2)

by 0x437A6FA: cupsDoRequest (in /usr/lib/libcups.so.2)

by 0x4358386: ??? (in /usr/lib/libcups.so.2)

by 0x4359D52: cupsGetDests2 (in /usr/lib/libcups.so.2)

by 0x435A1B4: cupsGetDests (in /usr/lib/libcups.so.2)

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

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

by 0x415D0EB: cv::fastMalloc(unsigned int) (in /usr/local/lib/libopencv_core.so.2.3.1)

by 0x4A5DE36: (below main) (libc-start.c:226) ---DrawImage is the only thing below main

67,108,864 bytes in 4 blocks are possibly lost in loss record 182 of 182

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

by 0x473C057: _capture_V4L2(CvCaptureCAM_V4L*, char*) (in /usr/lo开发者_C百科cal/lib/libopencv_highgui.so.2.3.1)


Well, at a minimum you never call SDL_FreeSurface() on atr.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号