Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: Lynne <dev@lynne.ee>
To: FFmpeg development discussions and patches <ffmpeg-devel@ffmpeg.org>
Subject: [FFmpeg-devel] [PATCH 4/5] hwcontext_vulkan: free temporary array once unneeded
Date: Tue, 13 Jun 2023 06:21:08 +0200 (CEST)
Message-ID: <NXmz5vr-03-9@lynne.ee> (raw)
In-Reply-To: <NXmyvDO--3-9@lynne.ee-NXmyy7U----9>

[-- Attachment #1: Type: text/plain, Size: 138 bytes --]

Fixes a small memory leak.
This also prevents leaks on malloc/mutex init errors.

Does not depend on any other patches.

Patch attached.


[-- Attachment #2: 0004-hwcontext_vulkan-free-temporary-array-once-unneeded.patch --]
[-- Type: text/x-diff, Size: 1746 bytes --]

From 52cdd121f986d36d18b95077f9c748bc9d7d918d Mon Sep 17 00:00:00 2001
From: Lynne <dev@lynne.ee>
Date: Tue, 13 Jun 2023 04:36:54 +0200
Subject: [PATCH 4/5] hwcontext_vulkan: free temporary array once unneeded

Fixes a small memory leak.
This also prevents leaks on malloc/mutex init errors.
---
 libavutil/hwcontext_vulkan.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/libavutil/hwcontext_vulkan.c b/libavutil/hwcontext_vulkan.c
index c86229ba65..ca802cc86e 100644
--- a/libavutil/hwcontext_vulkan.c
+++ b/libavutil/hwcontext_vulkan.c
@@ -1427,24 +1427,31 @@ static int vulkan_device_init(AVHWDeviceContext *ctx)
     vk->GetPhysicalDeviceQueueFamilyProperties(hwctx->phys_dev, &qf_num, qf);
 
     p->qf_mutex = av_calloc(qf_num, sizeof(*p->qf_mutex));
-    if (!p->qf_mutex)
+    if (!p->qf_mutex) {
+        av_free(qf);
         return AVERROR(ENOMEM);
+    }
     p->nb_tot_qfs = qf_num;
 
     for (uint32_t i = 0; i < qf_num; i++) {
         p->qf_mutex[i] = av_calloc(qf[i].queueCount, sizeof(**p->qf_mutex));
-        if (!p->qf_mutex[i])
+        if (!p->qf_mutex[i]) {
+            av_free(qf);
             return AVERROR(ENOMEM);
+        }
         for (uint32_t j = 0; j < qf[i].queueCount; j++) {
             err = pthread_mutex_init(&p->qf_mutex[i][j], NULL);
             if (err != 0) {
                 av_log(ctx, AV_LOG_ERROR, "pthread_mutex_init failed : %s\n",
                        av_err2str(err));
+                av_free(qf);
                 return AVERROR(err);
             }
         }
     }
 
+    av_free(qf);
+
     graph_index = hwctx->queue_family_index;
     comp_index  = hwctx->queue_family_comp_index;
     tx_index    = hwctx->queue_family_tx_index;
-- 
2.40.1


[-- Attachment #3: 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".

  parent reply	other threads:[~2023-06-13  4:21 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-13  4:18 [FFmpeg-devel] [RFC] [PATCH 1/5] hwcontext: add a new AVHWFramesContext.opaque field Lynne
     [not found] ` <NXmySQC--3-9@lynne.ee-NXmyWRF----9>
2023-06-13  4:19   ` [FFmpeg-devel] [PATCH 2/5] vulkan_decode: use the " Lynne
2023-06-13 12:28     ` Anton Khirnov
2023-06-13 12:53       ` Lynne
2023-06-18 11:10         ` Anton Khirnov
2023-06-18 12:20           ` Lynne
     [not found]   ` <NXmyk7P--3-9@lynne.ee-NXmynAe----9>
2023-06-13  4:20     ` [FFmpeg-devel] [PATCH 3/5] hwcontext_vulkan: call ff_vk_uninit() on device uninit Lynne
     [not found]     ` <NXmyvDO--3-9@lynne.ee-NXmyy7U----9>
2023-06-13  4:21       ` Lynne [this message]
     [not found]       ` <NXmz5vr-03-9@lynne.ee-NXmz8rg----9>
2023-06-13  4:24         ` [FFmpeg-devel] [PATCH 5/5] vulkan_decode: fix small memory leak Lynne
2023-06-15 20:03         ` [FFmpeg-devel] [PATCH 4/5] hwcontext_vulkan: free temporary array once unneeded Lynne
2023-06-15 20:03       ` [FFmpeg-devel] [PATCH 3/5] hwcontext_vulkan: call ff_vk_uninit() on device uninit Lynne
2023-06-13  4:44 ` [FFmpeg-devel] [RFC] [PATCH 1/5] hwcontext: add a new AVHWFramesContext.opaque field Andreas Rheinhardt
2023-06-13  4:48   ` Lynne
2023-06-13 16:57     ` Andreas Rheinhardt
2023-06-13 17:17       ` Lynne
     [not found]       ` <NXpkssV--3-9@lynne.ee-NXpkwTT----9>
2023-06-16 11:02         ` Lynne
     [not found]         ` <NY2rkbx--3-9@lynne.ee-NY2rofi----9>
2023-06-18 10:58           ` Lynne

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=NXmz5vr-03-9@lynne.ee \
    --to=dev@lynne.ee \
    --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