[Libav-user] (AVStream *)av_malloc(sizeof(AVStream)) crashed the application

Chandranath Bhattacharyya cbhattac at adobe.com
Tue Oct 30 12:11:40 CET 2012


> AVFormatContext *ic_enc_mjpeg;
> ic_enc_mjpeg = (AVFormatContext *)av_malloc(sizeof(AVFormatContext));
> ic_enc_mjpeg->streams[0] = (AVStream *)av_malloc(sizeof(AVStream));

> But
> ic_enc_mjpeg->streams[0] = (AVStream *)av_malloc(sizeof(AVStream));
> crashed the application.


AVFormatContext *ic_enc_mjpeg; //==> Here ic_enc_mjpeg is uninitialized.
ic_enc_mjpeg->streams[0] = (AVStream *)av_malloc(sizeof(AVStream));
=> ic_enc_mjpeg->stream[0] accesses uninitialized pointer ic_enc_mjpeg causing crash.

Situation is same as the following:
struct A {
    int a;
};
A *pa;
pA->a = 1; // crash

Regards,
Chandranath

From: libav-user-bounces at ffmpeg.org [mailto:libav-user-bounces at ffmpeg.org] On Behalf Of Wenpeng Zhou
Sent: 30 October 2012 16:35
To: 'This list is about using libavcodec, libavformat, libavutil, libavdevice and libavfilter.'
Subject: [Libav-user] (AVStream *)av_malloc(sizeof(AVStream)) crashed the application

Hi,
I use

AVFormatContext *ic_enc_mjpeg;
ic_enc_mjpeg = (AVFormatContext *)av_malloc(sizeof(AVFormatContext));
ic_enc_mjpeg->streams[0] = (AVStream *)av_malloc(sizeof(AVStream));

But
ic_enc_mjpeg->streams[0] = (AVStream *)av_malloc(sizeof(AVStream));
crashed the application.

I use VC++ 2010.

What is the reason?

Thanks!

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://ffmpeg.org/pipermail/libav-user/attachments/20121030/5066cec1/attachment.html>


More information about the Libav-user mailing list