zero sized malloc patch by Roman Shaposhnick

Originally committed as revision 1501 to svn://svn.ffmpeg.org/ffmpeg/trunk
This commit is contained in:
Roman Shaposhnik
2003-01-23 22:00:57 +00:00
committed by Fabrice Bellard
parent a5df11ab1e
commit 98486a6bc0
2 changed files with 22 additions and 12 deletions

View File

@@ -2457,9 +2457,12 @@ static int http_receive_data(HTTPContext *c)
if (!fmt_in) if (!fmt_in)
goto fail; goto fail;
s.priv_data = av_mallocz(fmt_in->priv_data_size); if (fmt_in->priv_data_size > 0) {
if (!s.priv_data) s.priv_data = av_mallocz(fmt_in->priv_data_size);
goto fail; if (!s.priv_data)
goto fail;
} else
s.priv_data = NULL;
if (fmt_in->read_header(&s, 0) < 0) { if (fmt_in->read_header(&s, 0) < 0) {
av_freep(&s.priv_data); av_freep(&s.priv_data);

View File

@@ -386,11 +386,14 @@ int av_open_input_file(AVFormatContext **ic_ptr, const char *filename,
} }
/* allocate private data */ /* allocate private data */
ic->priv_data = av_mallocz(fmt->priv_data_size); if (fmt->priv_data_size > 0) {
if (!ic->priv_data) { ic->priv_data = av_mallocz(fmt->priv_data_size);
err = AVERROR_NOMEM; if (!ic->priv_data) {
goto fail; err = AVERROR_NOMEM;
} goto fail;
}
} else
ic->priv_data = NULL;
/* default pts settings is MPEG like */ /* default pts settings is MPEG like */
av_set_pts_info(ic, 33, 1, 90000); av_set_pts_info(ic, 33, 1, 90000);
@@ -722,10 +725,14 @@ AVStream *av_new_stream(AVFormatContext *s, int id)
int av_set_parameters(AVFormatContext *s, AVFormatParameters *ap) int av_set_parameters(AVFormatContext *s, AVFormatParameters *ap)
{ {
int ret; int ret;
s->priv_data = av_mallocz(s->oformat->priv_data_size); if (s->oformat->priv_data_size > 0) {
if (!s->priv_data) s->priv_data = av_mallocz(s->oformat->priv_data_size);
return AVERROR_NOMEM; if (!s->priv_data)
return AVERROR_NOMEM;
} else
s->priv_data = NULL;
if (s->oformat->set_parameters) { if (s->oformat->set_parameters) {
ret = s->oformat->set_parameters(s, ap); ret = s->oformat->set_parameters(s, ap);
if (ret < 0) if (ret < 0)