[Libav-user] avpicture_free crashing when using with sws_scale()

Pradeep Karosiya praks411 at gmail.com
Tue Jun 25 12:52:41 CEST 2013


Hi 

I'm trying to encode images into video. I'm following muxing.c and scaling.c
examples. 
Though I'm able to encode a video, I'm not able to get rid of memory leaks.
I tried many different things
related related to allocation of AVPicture but still memory leaks. 
Specifically my code crashed when I call avpicture_free due to heap error.
Here is the snippet of code
void WriteFrame(const uchar* buf)  //Input buffer contained image data
{
if(need_conversion)
{
        AVPicture inpic;
        avpicture_alloc(&inpic,(PixelFormat)input_pix_fmt, width, height);
        avpicture_fill(&inpic, (uint8_t*)buf, (PixelFormat)input_pix_fmt,
width, height);
        struct SwsContext *img_convert_ctx = NULL;
        img_convert_ctx = sws_getContext(
            width,
            height,
            PIX_FMT_BGR24,
            c->width,
            c->height,
            c->pix_fmt,
            SWS_BICUBIC,
            NULL, NULL, NULL);

        if (sws_scale(
            img_convert_ctx, 
            inpic.data,
            inpic.linesize, 0,
            height,
            dst_picture.data, 
            dst_picture.linesize) < 0 )
        {
            std::cout<<"Conversion Failed "<<std::endl
        }

        avpicture_free(&inpic);  //Crashing here
        sws_freeContext(img_convert_ctx);
}
else
{
  avpicture_fill(&dst_picture,(uint8_t*)buf, (PixelFormat)input_pix_fmt,
width, height);

}
//Here I'm encoding the image into video
}
So no matter where I put my avpicture_free(&inpic) this is always crashing.
However If no conversion is required the everything works fine. Even if I
create inpic as global similar to dst_picture it again crashed.
Please suggest what could be going wrong.
Thanks and Regards,
Pradeep
       



--
View this message in context: http://libav-users.943685.n4.nabble.com/avpicture-free-crashing-when-using-with-sws-scale-tp4658017.html
Sent from the libav-users mailing list archive at Nabble.com.


More information about the Libav-user mailing list