Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

*** glibc detected *** : free() : invalid pointer c++ [duplicate]

I'm having some trouble when trying to execute the following code :https://github.com/Itseez/opencv/blob/master/samples/cpp/facedetect.cpp

With this modification in memory allocation:

for(;;)
{
 //   IplImage* iplImg = cvQueryFrame( capture );
        IplImage *iplImg = NULL ;
        iplImg = new IplImage ;
        iplImg = cvQueryFrame( capture);
   frame = cv::cvarrToMat(iplImg);
    if( frame.empty() )
        break;
    if( iplImg->origin == IPL_ORIGIN_TL )
        frame.copyTo( frameCopy );
    else
        flip( frame, frameCopy, 0 );
   // delete iplImg;
    free(iplImg);
    iplImg = NULL;
    detectAndDraw( frameCopy, cascade, nestedCascade, scale, tryflip );

    if( waitKey( 10 ) >= 0 )
        goto _cleanup_;
}

error glibc detected : ./facedetect free() : invalid pointer c++

I have used gprof to know the time executions of my functions here is the output of gprof image description

I want to reduce the time spent on release and detectAndDraw functions :p NB : is manual memory management in c++ better than automatic one ?? + using delete instead of free didn't solve my problem thanks for your help :)