[Libav-user] (AVStream *)av_malloc(sizeof(AVStream)) crashed the application
Chandranath Bhattacharyya
cbhattac at adobe.com
Tue Oct 30 12:28:06 CET 2012
>> 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/741216b6/attachment.html>
More information about the Libav-user
mailing list