From: James Almer <jamrial@gmail.com>
To: ffmpeg-devel@ffmpeg.org
Subject: Re: [FFmpeg-devel] [PATCH 01/11] avcodec/vulkan_encode_h264: Fix memleak on error
Date: Sat, 24 May 2025 23:49:45 -0300
Message-ID: <42333a6f-a5c0-4c60-84c7-3699d689bd7d@gmail.com> (raw)
In-Reply-To: <GV1P250MB0737150B57AB1453E4F40F628F8E2@GV1P250MB0737.EURP250.PROD.OUTLOOK.COM>
[-- Attachment #1.1.1: Type: text/plain, Size: 7087 bytes --]
On 5/5/2025 8:37 PM, Andreas Rheinhardt wrote:
> diff --git a/libavcodec/cbs_apv.c b/libavcodec/cbs_apv.c
> index ebf57d3bbb..ddc363fbf3 100644
> --- a/libavcodec/cbs_apv.c
> +++ b/libavcodec/cbs_apv.c
> @@ -276,12 +276,14 @@ static int cbs_apv_read_unit(CodedBitstreamContext *ctx,
> if (err < 0)
> return err;
>
> - // Each tile inside the frame has pointers into the unit
> - // data buffer; make a single reference here for all of
> - // them together.
> - frame->tile_data_ref = av_buffer_ref(unit->data_ref);
> - if (!frame->tile_data_ref)
> - return AVERROR(ENOMEM);
> + if (unit->data_ref) {
> + // Each tile inside the frame has pointers into the unit
> + // data buffer; make a single reference here for all of
> + // them together.
> + frame->tile_data_ref = av_buffer_ref(unit->data_ref);
> + if (!frame->tile_data_ref)
> + return AVERROR(ENOMEM);
> + }
> }
> break;
> case APV_PBU_ACCESS_UNIT_INFORMATION:
> diff --git a/libavcodec/cbs_av1.c b/libavcodec/cbs_av1.c
> index 4edb6ecd50..40c3cc8167 100644
> --- a/libavcodec/cbs_av1.c
> +++ b/libavcodec/cbs_av1.c
> @@ -824,9 +824,11 @@ static int cbs_av1_ref_tile_data(CodedBitstreamContext *ctx,
> // Must be byte-aligned at this point.
> av_assert0(pos % 8 == 0);
>
> - *data_ref = av_buffer_ref(unit->data_ref);
> - if (!*data_ref)
> - return AVERROR(ENOMEM);
> + if (unit->data_ref) {
> + *data_ref = av_buffer_ref(unit->data_ref);
> + if (!*data_ref)
> + return AVERROR(ENOMEM);
> + }
>
> *data = unit->data + pos / 8;
> *data_size = unit->data_size - pos / 8;
> diff --git a/libavcodec/cbs_h2645.c b/libavcodec/cbs_h2645.c
> index 369e3ac876..45b0c2ce87 100644
> --- a/libavcodec/cbs_h2645.c
> +++ b/libavcodec/cbs_h2645.c
> @@ -902,9 +902,11 @@ static int cbs_h264_read_nal_unit(CodedBitstreamContext *ctx,
> len = unit->data_size;
>
> slice->data_size = len - pos / 8;
> - slice->data_ref = av_buffer_ref(unit->data_ref);
> - if (!slice->data_ref)
> - return AVERROR(ENOMEM);
> + if (unit->data_ref) {
> + slice->data_ref = av_buffer_ref(unit->data_ref);
> + if (!slice->data_ref)
> + return AVERROR(ENOMEM);
> + }
> slice->data = unit->data + pos / 8;
> slice->data_bit_start = pos % 8;
> }
> @@ -1039,9 +1041,11 @@ static int cbs_h265_read_nal_unit(CodedBitstreamContext *ctx,
> len = unit->data_size;
>
> slice->data_size = len - pos / 8;
> - slice->data_ref = av_buffer_ref(unit->data_ref);
> - if (!slice->data_ref)
> - return AVERROR(ENOMEM);
> + if (unit->data_ref) {
> + slice->data_ref = av_buffer_ref(unit->data_ref);
> + if (!slice->data_ref)
> + return AVERROR(ENOMEM);
> + }
> slice->data = unit->data + pos / 8;
> slice->data_bit_start = pos % 8;
> }
> @@ -1205,9 +1209,11 @@ static int cbs_h266_read_nal_unit(CodedBitstreamContext *ctx,
>
> slice->header_size = pos / 8;
> slice->data_size = len - pos / 8;
> - slice->data_ref = av_buffer_ref(unit->data_ref);
> - if (!slice->data_ref)
> - return AVERROR(ENOMEM);
> + if (unit->data_ref) {
> + slice->data_ref = av_buffer_ref(unit->data_ref);
> + if (!slice->data_ref)
> + return AVERROR(ENOMEM);
> + }
> slice->data = unit->data + pos / 8;
> slice->data_bit_start = pos % 8;
> }
> diff --git a/libavcodec/cbs_jpeg.c b/libavcodec/cbs_jpeg.c
> index 281606e7af..cfb9b6d46c 100644
> --- a/libavcodec/cbs_jpeg.c
> +++ b/libavcodec/cbs_jpeg.c
> @@ -255,9 +255,11 @@ static int cbs_jpeg_read_unit(CodedBitstreamContext *ctx,
> av_assert0(pos % 8 == 0);
> if (pos > 0) {
> scan->data_size = unit->data_size - pos / 8;
> - scan->data_ref = av_buffer_ref(unit->data_ref);
> - if (!scan->data_ref)
> - return AVERROR(ENOMEM);
> + if (unit->data_ref) {
> + scan->data_ref = av_buffer_ref(unit->data_ref);
> + if (!scan->data_ref)
> + return AVERROR(ENOMEM);
> + }
> scan->data = unit->data + pos / 8;
> }
>
> diff --git a/libavcodec/cbs_mpeg2.c b/libavcodec/cbs_mpeg2.c
> index 37fc28a4e6..4b51647b13 100644
> --- a/libavcodec/cbs_mpeg2.c
> +++ b/libavcodec/cbs_mpeg2.c
> @@ -234,9 +234,11 @@ static int cbs_mpeg2_read_unit(CodedBitstreamContext *ctx,
> len = unit->data_size;
>
> slice->data_size = len - pos / 8;
> - slice->data_ref = av_buffer_ref(unit->data_ref);
> - if (!slice->data_ref)
> - return AVERROR(ENOMEM);
> + if (unit->data_ref) {
> + slice->data_ref = av_buffer_ref(unit->data_ref);
> + if (!slice->data_ref)
> + return AVERROR(ENOMEM);
> + }
> slice->data = unit->data + pos / 8;
>
> slice->data_bit_start = pos % 8;
> diff --git a/libavcodec/cbs_vp8.c b/libavcodec/cbs_vp8.c
> index 1f80f34faf..9bfba71d9e 100644
> --- a/libavcodec/cbs_vp8.c
> +++ b/libavcodec/cbs_vp8.c
> @@ -344,9 +344,11 @@ static int cbs_vp8_read_unit(CodedBitstreamContext *ctx,
> pos = (pos + 7) / 8;
> av_assert0(pos <= unit->data_size);
>
> - frame->data_ref = av_buffer_ref(unit->data_ref);
> - if (!frame->data_ref)
> - return AVERROR(ENOMEM);
> + if (unit->data_ref) {
> + frame->data_ref = av_buffer_ref(unit->data_ref);
> + if (!frame->data_ref)
> + return AVERROR(ENOMEM);
> + }
>
> frame->data = unit->data + pos;
> frame->data_size = unit->data_size - pos;
> diff --git a/libavcodec/cbs_vp9.c b/libavcodec/cbs_vp9.c
> index ff99fe32fb..3ca52770f3 100644
> --- a/libavcodec/cbs_vp9.c
> +++ b/libavcodec/cbs_vp9.c
> @@ -460,9 +460,11 @@ static int cbs_vp9_read_unit(CodedBitstreamContext *ctx,
> if (pos == unit->data_size) {
> // No data (e.g. a show-existing-frame frame).
> } else {
> - frame->data_ref = av_buffer_ref(unit->data_ref);
> - if (!frame->data_ref)
> - return AVERROR(ENOMEM);
> + if (unit->data_ref) {
> + frame->data_ref = av_buffer_ref(unit->data_ref);
> + if (!frame->data_ref)
> + return AVERROR(ENOMEM);
> + }
You can use av_buffer_replace() for all of these to simplify this change.
[-- Attachment #1.2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 495 bytes --]
[-- Attachment #2: Type: text/plain, Size: 251 bytes --]
_______________________________________________
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:[~2025-05-25 2:50 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-05 23:37 Andreas Rheinhardt
2025-05-07 13:16 ` Lynne
2025-05-25 2:49 ` James Almer [this message]
2025-05-25 2:52 ` James Almer
2025-06-01 20:45 ` Mark Thompson
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=42333a6f-a5c0-4c60-84c7-3699d689bd7d@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