fftools/cmdutils: add error handling to allocate_array_elem()

This commit is contained in:
Anton Khirnov
2023-07-13 17:50:16 +02:00
parent 8eb5adeab8
commit 6be4a29397
5 changed files with 51 additions and 14 deletions

View File

@@ -413,8 +413,11 @@ static const AVClass output_stream_class = {
static MuxStream *mux_stream_alloc(Muxer *mux, enum AVMediaType type)
{
const char *type_str = av_get_media_type_string(type);
MuxStream *ms = allocate_array_elem(&mux->of.streams, sizeof(*ms),
&mux->of.nb_streams);
MuxStream *ms;
ms = allocate_array_elem(&mux->of.streams, sizeof(*ms), &mux->of.nb_streams);
if (!ms)
return NULL;
ms->ost.file_index = mux->of.index;
ms->ost.index = mux->of.nb_streams - 1;
@@ -1101,6 +1104,9 @@ static int ost_add(Muxer *mux, const OptionsContext *o, enum AVMediaType type,
return AVERROR(ENOMEM);
ms = mux_stream_alloc(mux, type);
if (!ms)
return AVERROR(ENOMEM);
ost = &ms->ost;
if (o->streamid) {
@@ -2557,6 +2563,9 @@ static Muxer *mux_alloc(void)
{
Muxer *mux = allocate_array_elem(&output_files, sizeof(*mux), &nb_output_files);
if (!mux)
return NULL;
mux->of.class = &output_file_class;
mux->of.index = nb_output_files - 1;
@@ -2576,6 +2585,9 @@ int of_open(const OptionsContext *o, const char *filename)
int64_t stop_time = o->stop_time;
mux = mux_alloc();
if (!mux)
return AVERROR(ENOMEM);
of = &mux->of;
if (stop_time != INT64_MAX && recording_time != INT64_MAX) {