[Libav-user] (AVStream *)av_malloc(sizeof(AVStream)) crashed the application
Wenpeng Zhou
zhou.wenpeng at rdnet.fi
Tue Oct 30 12:34:58 CET 2012
Hi Chandranath and Geek.Song
Thanks!
I see.
I fixed as your suggested.
From: libav-user-bounces at ffmpeg.org [mailto:libav-user-bounces at ffmpeg.org]
On Behalf Of Chandranath Bhattacharyya
Sent: 30. lokakuuta 2012 13:28
To: This list is about using libavcodec, libavformat, libavutil, libavdevice
and libavfilter.
Subject: Re: [Libav-user] (AVStream *)av_malloc(sizeof(AVStream)) crashed
the application
>> Hi Chandranath
>> Thanks!
>> But I already allocated memory for the pointer *ic_enc_mjpeg
OK. Sorry. I did not realize you meant the crash occurred
even after allocation.
>> AVFormatContext *ic_enc_mjpeg;
>> ic_enc_mjpeg = (AVFormatContext *)av_malloc(sizeof(AVFormatContext));
>> Then I tried to allocate the memory for ic_enc_mjpeg->streams[0], then it
crashed.
streams variable inside AVFormatContext is AVStream **. So the allocation of
AVFormatContext using av_malloc is not supposed to initialize/allocate it.
Hence the crash.
Check the documentation in header avformat.h for more info.
The crash can be fixed by the following code.
AVFormatContext *ic_enc_mjpeg;
ic_enc_mjpeg = (AVFormatContext *)av_malloc(sizeof(AVFormatContext));
ic_enc_mjpeg->streams = (AVStream **)av_malloc(sizeof(AVStream *)); // ç DO
THIS.
ic_enc_mjpeg->nb_streams = 1; // OR WHATEVER.
ic_enc_mjpeg->streams[0] = (AVStream *)av_malloc(sizeof(AVStream));
Regards,
Chandranath
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://ffmpeg.org/pipermail/libav-user/attachments/20121030/662fed96/attachment.html>
More information about the Libav-user
mailing list