From: James Almer <jamrial@gmail.com>
To: ffmpeg-devel@ffmpeg.org
Subject: Re: [FFmpeg-devel] [PATCH 5/5] avformat/iamf_writer: Fix leaks on error
Date: Mon, 19 Feb 2024 18:55:52 -0300
Message-ID: <6819fbe8-7239-4890-bb9f-a40e35520613@gmail.com> (raw)
In-Reply-To: <AS8P250MB0744B44AA2E6D076A65382B68F512@AS8P250MB0744.EURP250.PROD.OUTLOOK.COM>
On 2/19/2024 6:52 PM, Andreas Rheinhardt wrote:
> Fixes Coverity issues #1559544 and #1559547.
>
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
> ---
> libavformat/iamf_writer.c | 42 +++++++++++++++++++++++++++------------
> 1 file changed, 29 insertions(+), 13 deletions(-)
>
> diff --git a/libavformat/iamf_writer.c b/libavformat/iamf_writer.c
> index e8a88b44c3..f6ebb4aaea 100644
> --- a/libavformat/iamf_writer.c
> +++ b/libavformat/iamf_writer.c
> @@ -240,12 +240,12 @@ int ff_iamf_add_audio_element(IAMFContext *iamf, const AVStreamGroup *stg, void
>
> audio_element->substreams = av_calloc(stg->nb_streams, sizeof(*audio_element->substreams));
> if (!audio_element->substreams)
> - return AVERROR(ENOMEM);
> + goto fail_enomem;
> audio_element->nb_substreams = stg->nb_streams;
>
> audio_element->layers = av_calloc(iamf_audio_element->nb_layers, sizeof(*audio_element->layers));
> if (!audio_element->layers)
> - return AVERROR(ENOMEM);
> + goto fail_enomem;
>
> for (int i = 0, j = 0; i < iamf_audio_element->nb_layers; i++) {
> int nb_channels = iamf_audio_element->layers[i]->ch_layout.nb_channels;
> @@ -266,7 +266,8 @@ int ff_iamf_add_audio_element(IAMFContext *iamf, const AVStreamGroup *stg, void
> if (nb_channels) {
> av_log(log_ctx, AV_LOG_ERROR, "Invalid channel count across substreams in layer %u from stream group %u\n",
> i, stg->index);
> - return AVERROR(EINVAL);
> + ret = AVERROR(EINVAL);
> + goto fail;
> }
> }
>
> @@ -276,13 +277,14 @@ int ff_iamf_add_audio_element(IAMFContext *iamf, const AVStreamGroup *stg, void
>
> if (param->nb_subblocks != 1) {
> av_log(log_ctx, AV_LOG_ERROR, "nb_subblocks in demixing_info for stream group %u is not 1\n", stg->index);
> - return AVERROR(EINVAL);
> + ret = AVERROR(EINVAL);
> + goto fail;
> }
>
> if (!param_definition) {
> param_definition = add_param_definition(iamf, param, audio_element, log_ctx);
> if (!param_definition)
> - return AVERROR(ENOMEM);
> + goto fail_enomem;
> }
> }
> if (iamf_audio_element->recon_gain_info) {
> @@ -291,29 +293,36 @@ int ff_iamf_add_audio_element(IAMFContext *iamf, const AVStreamGroup *stg, void
>
> if (param->nb_subblocks != 1) {
> av_log(log_ctx, AV_LOG_ERROR, "nb_subblocks in recon_gain_info for stream group %u is not 1\n", stg->index);
> - return AVERROR(EINVAL);
> + ret = AVERROR(EINVAL);
> + goto fail;
> }
>
> if (!param_definition) {
> param_definition = add_param_definition(iamf, param, audio_element, log_ctx);
> if (!param_definition)
> - return AVERROR(ENOMEM);
> + goto fail_enomem;
> }
> }
>
> tmp = av_realloc_array(iamf->audio_elements, iamf->nb_audio_elements + 1, sizeof(*iamf->audio_elements));
> if (!tmp)
> - return AVERROR(ENOMEM);
> + goto fail_enomem;
>
> iamf->audio_elements = tmp;
> iamf->audio_elements[iamf->nb_audio_elements++] = audio_element;
>
> return 0;
> +fail_enomem:
I prefer setting ret to ENOMEM before goto fail instead of adding a
second label for this.
> + ret = AVERROR(ENOMEM);
> +fail:
> + ff_iamf_free_audio_element(&audio_element);
> + return ret;
> }
>
> int ff_iamf_add_mix_presentation(IAMFContext *iamf, const AVStreamGroup *stg, void *log_ctx)
> {
> IAMFMixPresentation **tmp, *mix_presentation;
> + int ret;
>
> if (stg->type != AV_STREAM_GROUP_PARAMS_IAMF_MIX_PRESENTATION)
> return AVERROR(EINVAL);
> @@ -340,14 +349,15 @@ int ff_iamf_add_mix_presentation(IAMFContext *iamf, const AVStreamGroup *stg, vo
> if (!param) {
> av_log(log_ctx, AV_LOG_ERROR, "output_mix_config is not present in submix %u from "
> "Mix Presentation ID %"PRId64"\n", i, stg->id);
> - return AVERROR(EINVAL);
> + ret = AVERROR(EINVAL);
> + goto fail;
> }
>
> param_definition = ff_iamf_get_param_definition(iamf, param->parameter_id);
> if (!param_definition) {
> param_definition = add_param_definition(iamf, param, NULL, log_ctx);
> if (!param_definition)
> - return AVERROR(ENOMEM);
> + goto fail_enomem;
> }
>
> for (int j = 0; j < submix->nb_elements; j++) {
> @@ -357,25 +367,31 @@ int ff_iamf_add_mix_presentation(IAMFContext *iamf, const AVStreamGroup *stg, vo
> if (!param) {
> av_log(log_ctx, AV_LOG_ERROR, "element_mix_config is not present for element %u in submix %u from "
> "Mix Presentation ID %"PRId64"\n", j, i, stg->id);
> - return AVERROR(EINVAL);
> + ret = AVERROR(EINVAL);
> + goto fail;
> }
> param_definition = ff_iamf_get_param_definition(iamf, param->parameter_id);
> if (!param_definition) {
> param_definition = add_param_definition(iamf, param, NULL, log_ctx);
> if (!param_definition)
> - return AVERROR(ENOMEM);
> + goto fail_enomem;
> }
> }
> }
>
> tmp = av_realloc_array(iamf->mix_presentations, iamf->nb_mix_presentations + 1, sizeof(*iamf->mix_presentations));
> if (!tmp)
> - return AVERROR(ENOMEM);
> + goto fail_enomem;
>
> iamf->mix_presentations = tmp;
> iamf->mix_presentations[iamf->nb_mix_presentations++] = mix_presentation;
>
> return 0;
> +fail_enomem:
> + ret = AVERROR(ENOMEM);
> +fail:
> + ff_iamf_free_mix_presentation(&mix_presentation);
> + return ret;
> }
>
> static int iamf_write_codec_config(const IAMFContext *iamf,
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
next prev parent reply other threads:[~2024-02-19 21:56 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-19 21:51 [FFmpeg-devel] [PATCH 1/5] avformat/iamf_writer: Don't leak on error when adding ParamDefinition Andreas Rheinhardt
2024-02-19 21:52 ` [FFmpeg-devel] [PATCH 2/5] avformat/iamf_writer: Remove nonsense check Andreas Rheinhardt
2024-02-19 21:57 ` James Almer
2024-02-19 21:52 ` [FFmpeg-devel] [PATCH 3/5] avformat/iamf_writer: Don't memset twice Andreas Rheinhardt
2024-02-19 21:57 ` James Almer
2024-02-19 21:52 ` [FFmpeg-devel] [PATCH 4/5] avformat/iamf: Don't mix ownership and non-ownership pointers Andreas Rheinhardt
2024-02-19 22:03 ` James Almer
2024-02-19 22:06 ` Andreas Rheinhardt
2024-02-19 22:06 ` James Almer
2024-02-19 21:52 ` [FFmpeg-devel] [PATCH 5/5] avformat/iamf_writer: Fix leaks on error Andreas Rheinhardt
2024-02-19 21:55 ` James Almer [this message]
2024-02-19 22:17 ` [FFmpeg-devel] [PATCH v2 5/6] avformat/iamf_writer: Return proper error codes Andreas Rheinhardt
2024-02-19 22:22 ` James Almer
2024-02-19 22:17 ` [FFmpeg-devel] [PATCH v2 6/6] avformat/iamf_writer: Fix leaks on error Andreas Rheinhardt
2024-02-19 22:19 ` James Almer
2024-02-19 22:19 ` [FFmpeg-devel] [PATCH 1/5] avformat/iamf_writer: Don't leak on error when adding ParamDefinition James Almer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=6819fbe8-7239-4890-bb9f-a40e35520613@gmail.com \
--to=jamrial@gmail.com \
--cc=ffmpeg-devel@ffmpeg.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
This inbox may be cloned and mirrored by anyone:
git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git
# If you have public-inbox 1.1+ installed, you may
# initialize and index your mirror using the following commands:
public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
ffmpegdev@gitmailbox.com
public-inbox-index ffmpegdev
Example config snippet for mirrors.
AGPL code for this site: git clone https://public-inbox.org/public-inbox.git