*** 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
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 :)
you shall start changing the cote to the C++ version... C-API is deprecated
please avoid using IplImage * and cv* functions. stay away from new/delete malloc/free and use cv::Mat, please.
@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, 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
in the meantime, use the tutorial code