[Libav-user] avpicture_free crashing when using with sws_scale()
Stefano Sabatini
stefasab at gmail.com
Tue Jun 25 23:44:09 CEST 2013
On date Tuesday 2013-06-25 03:52:41 -0700, Pradeep Karosiya encoded:
> 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);
Here you're allocating an image in inpic, and setting the data and
linesize pointers.
> avpicture_fill(&inpic, (uint8_t*)buf, (PixelFormat)input_pix_fmt,
> width, height);
Here you're filling inpic with the buffer in buf (assuming align =
1). Now you destroyed the reference to the previously allocated data
-> leak.
> 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
here you're freeing the buf data, which maybe does not belong to the
heap?
[...]
More information about the Libav-user
mailing list