Fixes Coverity issues #1559544 and #1559547.
Showing the changes to libavformat (1 of 1 file). Show all
Unified · Split
| @@ -239,13 +239,17 @@ int ff_iamf_add_audio_element(IAMFContext *iamf, const AVStreamGroup *stg, void · 238 unmodified lines | |||
| 239 | audio_element->codec_config_id = ret; | 239 | audio_element->codec_config_id = ret; |
| 240 | 240 | ||
| 241 | audio_element->substreams = av_calloc(stg->nb_streams, sizeof(*audio_element->substreams)); | 241 | audio_element->substreams = av_calloc(stg->nb_streams, sizeof(*audio_element->substreams)); |
| 242 | if (!audio_element->substreams) | 242 | if (!audio_element->substreams) { |
| 243 | return AVERROR(ENOMEM); | 243 | ret = AVERROR(ENOMEM); |
| 244 | goto fail; | ||
| 245 | } | ||
| 244 | audio_element->nb_substreams = stg->nb_streams; | 246 | audio_element->nb_substreams = stg->nb_streams; |
| 245 | 247 | ||
| 246 | audio_element->layers = av_calloc(iamf_audio_element->nb_layers, sizeof(*audio_element->layers)); | 248 | audio_element->layers = av_calloc(iamf_audio_element->nb_layers, sizeof(*audio_element->layers)); |
| 247 | if (!audio_element->layers) | 249 | if (!audio_element->layers) { |
| 248 | return AVERROR(ENOMEM); | 250 | ret = AVERROR(ENOMEM); |
| 251 | goto fail; | ||
| 252 | } | ||
| 249 | 253 | ||
| 250 | for (int i = 0, j = 0; i < iamf_audio_element->nb_layers; i++) { | 254 | for (int i = 0, j = 0; i < iamf_audio_element->nb_layers; i++) { |
| 251 | int nb_channels = iamf_audio_element->layers[i]->ch_layout.nb_channels; | 255 | 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 | |||
| 266 | if (nb_channels) { | 270 | if (nb_channels) { |
| 267 | av_log(log_ctx, AV_LOG_ERROR, "Invalid channel count across substreams in layer %u from stream group %u\n", | 271 | av_log(log_ctx, AV_LOG_ERROR, "Invalid channel count across substreams in layer %u from stream group %u\n", |
| 268 | i, stg->index); | 272 | i, stg->index); |
| 269 | return AVERROR(EINVAL); | 273 | ret = AVERROR(EINVAL); |
| 274 | goto fail; | ||
| 270 | } | 275 | } |
| 271 | } | 276 | } |
| 272 | 277 | ||
| @@ -276,13 +281,14 @@ int ff_iamf_add_audio_element(IAMFContext *iamf, const AVStreamGroup *stg, void · 3 unmodified lines | |||
| 276 | 281 | ||
| 277 | if (param->nb_subblocks != 1) { | 282 | if (param->nb_subblocks != 1) { |
| 278 | av_log(log_ctx, AV_LOG_ERROR, "nb_subblocks in demixing_info for stream group %u is not 1\n", stg->index); | 283 | 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; | ||
| 280 | } | 286 | } |
| 281 | 287 | ||
| 282 | if (!param_definition) { | 288 | if (!param_definition) { |
| 283 | ret = add_param_definition(iamf, param, audio_element, log_ctx); | 289 | ret = add_param_definition(iamf, param, audio_element, log_ctx); |
| 284 | if (ret < 0) | 290 | if (ret < 0) |
| 285 | return ret; | 291 | goto fail; |
| 286 | } | 292 | } |
| 287 | } | 293 | } |
| 288 | if (iamf_audio_element->recon_gain_info) { | 294 | 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 | |||
| 291 | 297 | ||
| 292 | if (param->nb_subblocks != 1) { | 298 | if (param->nb_subblocks != 1) { |
| 293 | av_log(log_ctx, AV_LOG_ERROR, "nb_subblocks in recon_gain_info for stream group %u is not 1\n", stg->index); | 299 | 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; | ||
| 295 | } | 302 | } |
| 296 | 303 | ||
| 297 | if (!param_definition) { | 304 | if (!param_definition) { |
| 298 | ret = add_param_definition(iamf, param, audio_element, log_ctx); | 305 | ret = add_param_definition(iamf, param, audio_element, log_ctx); |
| 299 | if (ret < 0) | 306 | if (ret < 0) |
| 300 | return ret; | 307 | goto fail; |
| 301 | } | 308 | } |
| 302 | } | 309 | } |
| 303 | 310 | ||
| 304 | tmp = av_realloc_array(iamf->audio_elements, iamf->nb_audio_elements + 1, sizeof(*iamf->audio_elements)); | 311 | tmp = av_realloc_array(iamf->audio_elements, iamf->nb_audio_elements + 1, sizeof(*iamf->audio_elements)); |
| 305 | if (!tmp) | 312 | if (!tmp) { |
| 306 | return AVERROR(ENOMEM); | 313 | ret = AVERROR(ENOMEM); |
| 314 | goto fail; | ||
| 315 | } | ||
| 307 | 316 | ||
| 308 | iamf->audio_elements = tmp; | 317 | iamf->audio_elements = tmp; |
| 309 | iamf->audio_elements[iamf->nb_audio_elements++] = audio_element; | 318 | iamf->audio_elements[iamf->nb_audio_elements++] = audio_element; |
| 310 | 319 | ||
| 311 | return 0; | 320 | return 0; |
| 321 | fail: | ||
| 322 | ff_iamf_free_audio_element(&audio_element); | ||
| 323 | return ret; | ||
| 312 | } | 324 | } |
| 313 | 325 | ||
| 314 | int ff_iamf_add_mix_presentation(IAMFContext *iamf, const AVStreamGroup *stg, void *log_ctx) | 326 | 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 | |||
| 341 | if (!param) { | 353 | if (!param) { |
| 342 | av_log(log_ctx, AV_LOG_ERROR, "output_mix_config is not present in submix %u from " | 354 | av_log(log_ctx, AV_LOG_ERROR, "output_mix_config is not present in submix %u from " |
| 343 | "Mix Presentation ID %"PRId64"\n", i, stg->id); | 355 | "Mix Presentation ID %"PRId64"\n", i, stg->id); |
| 344 | return AVERROR(EINVAL); | 356 | ret = AVERROR(EINVAL); |
| 357 | goto fail; | ||
| 345 | } | 358 | } |
| 346 | 359 | ||
| 347 | param_definition = ff_iamf_get_param_definition(iamf, param->parameter_id); | 360 | param_definition = ff_iamf_get_param_definition(iamf, param->parameter_id); |
| 348 | if (!param_definition) { | 361 | if (!param_definition) { |
| 349 | ret = add_param_definition(iamf, param, NULL, log_ctx); | 362 | ret = add_param_definition(iamf, param, NULL, log_ctx); |
| 350 | if (ret < 0) | 363 | if (ret < 0) |
| 351 | return ret; | 364 | goto fail; |
| 352 | } | 365 | } |
| 353 | 366 | ||
| 354 | for (int j = 0; j < submix->nb_elements; j++) { | 367 | 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 | |||
| 358 | if (!param) { | 371 | if (!param) { |
| 359 | av_log(log_ctx, AV_LOG_ERROR, "element_mix_config is not present for element %u in submix %u from " | 372 | av_log(log_ctx, AV_LOG_ERROR, "element_mix_config is not present for element %u in submix %u from " |
| 360 | "Mix Presentation ID %"PRId64"\n", j, i, stg->id); | 373 | "Mix Presentation ID %"PRId64"\n", j, i, stg->id); |
| 361 | return AVERROR(EINVAL); | 374 | ret = AVERROR(EINVAL); |
| 375 | goto fail; | ||
| 362 | } | 376 | } |
| 363 | param_definition = ff_iamf_get_param_definition(iamf, param->parameter_id); | 377 | param_definition = ff_iamf_get_param_definition(iamf, param->parameter_id); |
| 364 | if (!param_definition) { | 378 | if (!param_definition) { |
| 365 | ret = add_param_definition(iamf, param, NULL, log_ctx); | 379 | ret = add_param_definition(iamf, param, NULL, log_ctx); |
| 366 | if (ret < 0) | 380 | if (ret < 0) |
| 367 | return ret; | 381 | goto fail; |
| 368 | } | 382 | } |
| 369 | } | 383 | } |
| 370 | } | 384 | } |
| 371 | 385 | ||
| 372 | tmp = av_realloc_array(iamf->mix_presentations, iamf->nb_mix_presentations + 1, sizeof(*iamf->mix_presentations)); | 386 | tmp = av_realloc_array(iamf->mix_presentations, iamf->nb_mix_presentations + 1, sizeof(*iamf->mix_presentations)); |
| 373 | if (!tmp) | 387 | if (!tmp) { |
| 374 | return AVERROR(ENOMEM); | 388 | ret = AVERROR(ENOMEM); |
| 389 | goto fail; | ||
| 390 | } | ||
| 375 | 391 | ||
| 376 | iamf->mix_presentations = tmp; | 392 | iamf->mix_presentations = tmp; |
| 377 | iamf->mix_presentations[iamf->nb_mix_presentations++] = mix_presentation; | 393 | iamf->mix_presentations[iamf->nb_mix_presentations++] = mix_presentation; |
| 378 | 394 | ||
| 379 | return 0; | 395 | return 0; |
| 396 | fail: | ||
| 397 | ff_iamf_free_mix_presentation(&mix_presentation); | ||
| 398 | return ret; | ||
| 380 | } | 399 | } |
| 381 | 400 | ||
| 382 | static int iamf_write_codec_config(const IAMFContext *iamf, | 401 | static int iamf_write_codec_config(const IAMFContext *iamf, |