History

avformat/iamf_writer: Fix leaks on error

Fixes Coverity issues #1559544 and #1559547.

Andreas Rheinhardt committed 2 years ago

Commit 1f7cd5d1 parent c5845af1 file · +36 −17Browse files

Showing the changes to libavformat (1 of 1 file). Show all

Unified · Split

libavformat/iamf_writer.c+36−17
@@ -239,13 +239,17 @@ int ff_iamf_add_audio_element(IAMFContext *iamf, const AVStreamGroup *stg, void · 238 unmodified lines
239239 audio_element->codec_config_id = ret;
240240
241241 audio_element->substreams = av_calloc(stg->nb_streams, sizeof(*audio_element->substreams));
242− if (!audio_element->substreams)
243− return AVERROR(ENOMEM);
242+ if (!audio_element->substreams) {
243+ ret = AVERROR(ENOMEM);
244+ goto fail;
245+ }
244246 audio_element->nb_substreams = stg->nb_streams;
245247
246248 audio_element->layers = av_calloc(iamf_audio_element->nb_layers, sizeof(*audio_element->layers));
247− if (!audio_element->layers)
248− return AVERROR(ENOMEM);
249+ if (!audio_element->layers) {
250+ ret = AVERROR(ENOMEM);
251+ goto fail;
252+ }
249253
250254 for (int i = 0, j = 0; i < iamf_audio_element->nb_layers; i++) {
251255 int nb_channels = iamf_audio_element->layers[i]->ch_layout.nb_channels;
@@ -266,7 +270,8 @@ int ff_iamf_add_audio_element(IAMFContext *iamf, const AVStreamGroup *stg, void · 14 unmodified lines
266270 if (nb_channels) {
267271 av_log(log_ctx, AV_LOG_ERROR, "Invalid channel count across substreams in layer %u from stream group %u\n",
268272 i, stg->index);
269− return AVERROR(EINVAL);
273+ ret = AVERROR(EINVAL);
274+ goto fail;
270275 }
271276 }
272277
@@ -276,13 +281,14 @@ int ff_iamf_add_audio_element(IAMFContext *iamf, const AVStreamGroup *stg, void · 3 unmodified lines
276281
277282 if (param->nb_subblocks != 1) {
278283 av_log(log_ctx, AV_LOG_ERROR, "nb_subblocks in demixing_info for stream group %u is not 1\n", stg->index);
279− return AVERROR(EINVAL);
284+ ret = AVERROR(EINVAL);
285+ goto fail;
280286 }
281287
282288 if (!param_definition) {
283289 ret = add_param_definition(iamf, param, audio_element, log_ctx);
284290 if (ret < 0)
285− return ret;
291+ goto fail;
286292 }
287293 }
288294 if (iamf_audio_element->recon_gain_info) {
@@ -291,24 +297,30 @@ int ff_iamf_add_audio_element(IAMFContext *iamf, const AVStreamGroup *stg, void · 2 unmodified lines
291297
292298 if (param->nb_subblocks != 1) {
293299 av_log(log_ctx, AV_LOG_ERROR, "nb_subblocks in recon_gain_info for stream group %u is not 1\n", stg->index);
294− return AVERROR(EINVAL);
300+ ret = AVERROR(EINVAL);
301+ goto fail;
295302 }
296303
297304 if (!param_definition) {
298305 ret = add_param_definition(iamf, param, audio_element, log_ctx);
299306 if (ret < 0)
300− return ret;
307+ goto fail;
301308 }
302309 }
303310
304311 tmp = av_realloc_array(iamf->audio_elements, iamf->nb_audio_elements + 1, sizeof(*iamf->audio_elements));
305− if (!tmp)
306− return AVERROR(ENOMEM);
312+ if (!tmp) {
313+ ret = AVERROR(ENOMEM);
314+ goto fail;
315+ }
307316
308317 iamf->audio_elements = tmp;
309318 iamf->audio_elements[iamf->nb_audio_elements++] = audio_element;
310319
311320 return 0;
321+fail:
322+ ff_iamf_free_audio_element(&audio_element);
323+ return ret;
312324 }
313325
314326 int ff_iamf_add_mix_presentation(IAMFContext *iamf, const AVStreamGroup *stg, void *log_ctx)
@@ -341,14 +353,15 @@ int ff_iamf_add_mix_presentation(IAMFContext *iamf, const AVStreamGroup *stg, vo · 26 unmodified lines
341353 if (!param) {
342354 av_log(log_ctx, AV_LOG_ERROR, "output_mix_config is not present in submix %u from "
343355 "Mix Presentation ID %"PRId64"\n", i, stg->id);
344− return AVERROR(EINVAL);
356+ ret = AVERROR(EINVAL);
357+ goto fail;
345358 }
346359
347360 param_definition = ff_iamf_get_param_definition(iamf, param->parameter_id);
348361 if (!param_definition) {
349362 ret = add_param_definition(iamf, param, NULL, log_ctx);
350363 if (ret < 0)
351− return ret;
364+ goto fail;
352365 }
353366
354367 for (int j = 0; j < submix->nb_elements; j++) {
@@ -358,25 +371,31 @@ int ff_iamf_add_mix_presentation(IAMFContext *iamf, const AVStreamGroup *stg, vo · 3 unmodified lines
358371 if (!param) {
359372 av_log(log_ctx, AV_LOG_ERROR, "element_mix_config is not present for element %u in submix %u from "
360373 "Mix Presentation ID %"PRId64"\n", j, i, stg->id);
361− return AVERROR(EINVAL);
374+ ret = AVERROR(EINVAL);
375+ goto fail;
362376 }
363377 param_definition = ff_iamf_get_param_definition(iamf, param->parameter_id);
364378 if (!param_definition) {
365379 ret = add_param_definition(iamf, param, NULL, log_ctx);
366380 if (ret < 0)
367− return ret;
381+ goto fail;
368382 }
369383 }
370384 }
371385
372386 tmp = av_realloc_array(iamf->mix_presentations, iamf->nb_mix_presentations + 1, sizeof(*iamf->mix_presentations));
373− if (!tmp)
374− return AVERROR(ENOMEM);
387+ if (!tmp) {
388+ ret = AVERROR(ENOMEM);
389+ goto fail;
390+ }
375391
376392 iamf->mix_presentations = tmp;
377393 iamf->mix_presentations[iamf->nb_mix_presentations++] = mix_presentation;
378394
379395 return 0;
396+fail:
397+ ff_iamf_free_mix_presentation(&mix_presentation);
398+ return ret;
380399 }
381400
382401 static int iamf_write_codec_config(const IAMFContext *iamf,

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t