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

asked 2015-07-13 07:26:45 -0600

franken gravatar image

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

edit retag flag offensive close merge delete

Comments

you shall start changing the cote to the C++ version... C-API is deprecated

thdrksdfthmn gravatar imagethdrksdfthmn ( 2015-07-13 07:32:38 -0600 )edit
1

please avoid using IplImage * and cv* functions. stay away from new/delete malloc/free and use cv::Mat, please.

berak gravatar imageberak ( 2015-07-13 07:39:14 -0600 )edit
1

@berak so you are seiing that i must use automatic memory management ? however i found this example on the latest version of opencv 3 gold why they still keeping it ? thnaks

franken gravatar imagefranken ( 2015-07-13 08:55:23 -0600 )edit

@franken, oh, apologies for the wrong attribution of the flaws there.

you found an outdated sample , thanks for the notice, let's immediately change this ;)

and yes, as long as you are new to all of it, you must play by the rules, and use automatic memory management supplied by cv::Mat

btw, if you don't like it, and want to stay closer to your c-roots (if any) have a look at pico

berak gravatar imageberak ( 2015-07-13 09:06:06 -0600 )edit

in the meantime, use the tutorial code

berak gravatar imageberak ( 2015-07-13 09:20:22 -0600 )edit