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 | 239 | audio_element->codec_config_id = ret; |
| 240 | 240 | |
| 241 | 241 | 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 | + } | |
| 244 | 246 | audio_element->nb_substreams = stg->nb_streams; |
| 245 | 247 | |
| 246 | 248 | 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 | + } | |
| 249 | 253 | |
| 250 | 254 | for (int i = 0, j = 0; i < iamf_audio_element->nb_layers; i++) { |
| 251 | 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 | 270 | if (nb_channels) { |
| 267 | 271 | av_log(log_ctx, AV_LOG_ERROR, "Invalid channel count across substreams in layer %u from stream group %u\n", |
| 268 | 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 | 282 | if (param->nb_subblocks != 1) { |
| 278 | 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 | 288 | if (!param_definition) { |
| 283 | 289 | ret = add_param_definition(iamf, param, audio_element, log_ctx); |
| 284 | 290 | if (ret < 0) |
| 285 | − return ret; | |
| 291 | + goto fail; | |
| 286 | 292 | } |
| 287 | 293 | } |
| 288 | 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 | 298 | if (param->nb_subblocks != 1) { |
| 293 | 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 | 304 | if (!param_definition) { |
| 298 | 305 | ret = add_param_definition(iamf, param, audio_element, log_ctx); |
| 299 | 306 | if (ret < 0) |
| 300 | − return ret; | |
| 307 | + goto fail; | |
| 301 | 308 | } |
| 302 | 309 | } |
| 303 | 310 | |
| 304 | 311 | 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 | + } | |
| 307 | 316 | |
| 308 | 317 | iamf->audio_elements = tmp; |
| 309 | 318 | iamf->audio_elements[iamf->nb_audio_elements++] = audio_element; |
| 310 | 319 | |
| 311 | 320 | return 0; |
| 321 | +fail: | |
| 322 | + ff_iamf_free_audio_element(&audio_element); | |
| 323 | + return ret; | |
| 312 | 324 | } |
| 313 | 325 | |
| 314 | 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 | 353 | if (!param) { |
| 342 | 354 | av_log(log_ctx, AV_LOG_ERROR, "output_mix_config is not present in submix %u from " |
| 343 | 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 | 360 | param_definition = ff_iamf_get_param_definition(iamf, param->parameter_id); |
| 348 | 361 | if (!param_definition) { |
| 349 | 362 | ret = add_param_definition(iamf, param, NULL, log_ctx); |
| 350 | 363 | if (ret < 0) |
| 351 | − return ret; | |
| 364 | + goto fail; | |
| 352 | 365 | } |
| 353 | 366 | |
| 354 | 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 | 371 | if (!param) { |
| 359 | 372 | av_log(log_ctx, AV_LOG_ERROR, "element_mix_config is not present for element %u in submix %u from " |
| 360 | 373 | "Mix Presentation ID %"PRId64"\n", j, i, stg->id); |
| 361 | − return AVERROR(EINVAL); | |
| 374 | + ret = AVERROR(EINVAL); | |
| 375 | + goto fail; | |
| 362 | 376 | } |
| 363 | 377 | param_definition = ff_iamf_get_param_definition(iamf, param->parameter_id); |
| 364 | 378 | if (!param_definition) { |
| 365 | 379 | ret = add_param_definition(iamf, param, NULL, log_ctx); |
| 366 | 380 | if (ret < 0) |
| 367 | − return ret; | |
| 381 | + goto fail; | |
| 368 | 382 | } |
| 369 | 383 | } |
| 370 | 384 | } |
| 371 | 385 | |
| 372 | 386 | 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 | + } | |
| 375 | 391 | |
| 376 | 392 | iamf->mix_presentations = tmp; |
| 377 | 393 | iamf->mix_presentations[iamf->nb_mix_presentations++] = mix_presentation; |
| 378 | 394 | |
| 379 | 395 | return 0; |
| 396 | +fail: | |
| 397 | + ff_iamf_free_mix_presentation(&mix_presentation); | |
| 398 | + return ret; | |
| 380 | 399 | } |
| 381 | 400 | |
| 382 | 401 | static int iamf_write_codec_config(const IAMFContext *iamf, |