From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id 2E82C4BA06 for ; Tue, 9 Jul 2024 14:41:13 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id D85F768DCC1; Tue, 9 Jul 2024 17:41:10 +0300 (EEST) Received: from haasn.dev (haasn.dev [78.46.187.166]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 176B168DBF8 for ; Tue, 9 Jul 2024 17:41:05 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=haasn.xyz; s=mail; t=1720536064; bh=j6fDMzi7B1xAbhvwXW01NLjDTujJ8m+ax++XMO36UQU=; h=From:To:Cc:Subject:Date:From; b=qK4T4IraQg+TFn7Nxl0ZO8nvp1Tf0zwT73PKaA635tzLKCWQoPmwW7RpjL9qprE+N 3eR156yoWOjormsiMBbXwROFhWOfRvGw74a0ahy97aCOVghV4WJsyigmjTQMUobSiZ FikfWaaQfD4WNamnHM4PEprx6ojbRrfnZMAlR74A= Received: from localhost (unknown [217.111.52.58]) by haasn.dev (Postfix) with ESMTPSA id A5DEC406C7; Tue, 9 Jul 2024 16:41:04 +0200 (CEST) From: Niklas Haas To: ffmpeg-devel@ffmpeg.org Date: Tue, 9 Jul 2024 16:41:01 +0200 Message-ID: <20240709144101.25919-1-ffmpeg@haasn.xyz> X-Mailer: git-send-email 2.44.0 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] swscale/utils: fix leak on threaded ctx init failure X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Niklas Haas Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: From: Niklas Haas This count gets incremented after init succeeds, when it should be incremented after *alloc* succeeds. Otherwise, we leak the context on failure. There are no negative consequences of incrementing for allocated-but-not-initialized contexts, as the only functions that reference it will, in the worst case, simply behave as if called on allocated-but-not-initialized contexts, which is in line with expected behavior when sws_init_context() fails. --- libswscale/utils.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/libswscale/utils.c b/libswscale/utils.c index 12dba712c1..6ac5b202b0 100644 --- a/libswscale/utils.c +++ b/libswscale/utils.c @@ -2046,6 +2046,7 @@ static int context_init_threaded(SwsContext *c, if (!c->slice_ctx[i]) return AVERROR(ENOMEM); + c->nb_slice_ctx++; c->slice_ctx[i]->parent = c; ret = av_opt_copy((void*)c->slice_ctx[i], (void*)c); @@ -2058,8 +2059,6 @@ static int context_init_threaded(SwsContext *c, if (ret < 0) return ret; - c->nb_slice_ctx++; - if (c->slice_ctx[i]->dither == SWS_DITHER_ED) { av_log(c, AV_LOG_VERBOSE, "Error-diffusion dither is in use, scaling will be single-threaded."); -- 2.44.0 _______________________________________________ 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".