From patchwork Wed Mar 10 21:54:40 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 26328 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id DACC444B799 for ; Wed, 10 Mar 2021 23:55:51 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id C1A5C68ABB7; Wed, 10 Mar 2021 23:55:51 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ej1-f43.google.com (mail-ej1-f43.google.com [209.85.218.43]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 985FA68AB25 for ; Wed, 10 Mar 2021 23:55:39 +0200 (EET) Received: by mail-ej1-f43.google.com with SMTP id lr13so41886414ejb.8 for ; Wed, 10 Mar 2021 13:55:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references:reply-to :mime-version:content-transfer-encoding; bh=buO2r/hEIed8PYuB7UVi5fPGeQIKUFoHhTjs/y+L/mM=; b=OK2K+bkYdPpobPV96xT+fIJYaogpCnE5OGFxEKAIc6XygRKPaItw2dfgzuwcN5kbMt RULqrz7KRlxsId6A8iOC+1licRoOc+eFrQLneQcV2UhqwO083G1DKut5jK28FMlAXy3k siv8VHrSQbZlmiwt2HL3mWNCitl3hCCKUydUs7r4YST+8Mz2p159e3zkCjS6j+uBeUJh FD7mC6omsg/sv6jhUSS1iBGtPXDrD6jTCbaggKvw5C3JcT1ADJ4BjLass3Cq9gu9wfid l1PsiWMdCyeoXdGmApLleWnfh/bb3UICaXrLo4Wy7z9VBGw5zQEV1GClDrDij44Yc7TD /JeQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:reply-to:mime-version:content-transfer-encoding; bh=buO2r/hEIed8PYuB7UVi5fPGeQIKUFoHhTjs/y+L/mM=; b=CGWCrzvaFjmFwqmkxI41Aze5bXiU5/CjwCU0n1DFOHr8SysxGHi6hPNFa8DfFfUpGq QW3nS+YJhW/XzQL2eScRtq59N1qw7I8OqGn6Z/+kVyVUFrE2uxsJogB1Kc0w7jdR+OiT NtAEJMe+gmCaxWksnMiBmbFaKXcOhcrMRnR21R4ByypVdV88P6WZkdX5sT9u2KH8g3xn BOWUMQNP7vcmz/ciPaSZRNEYLfwdzunwrImpn8if+KOGR/yRyMOh3YbFOZOLE2yNszUc Y2ymB/G2FnY5yMfRIUmokqo911QhiWF+jKF7GNblx5fjqGLuhcuxjS38IwylbuaaDM8E QPBg== X-Gm-Message-State: AOAM5322WXjpfa77fr+3YdIDgQ6Lzgr5dZkmB3XmIaI+pPdEWC6bzmuz ua+zoZPyC+YY4KHUrt8HrTLzav+7eGE= X-Google-Smtp-Source: ABdhPJxnFNXpA5Y0/f4f4E6g14UAUBli2x8MoeJKNmOm895vr9bivQr4CFZsGTHvbr+t2rZKLk4Fcw== X-Received: by 2002:a17:906:af91:: with SMTP id mj17mr32448ejb.230.1615413338859; Wed, 10 Mar 2021 13:55:38 -0800 (PST) Received: from sblaptop.fritz.box (ipbcc1aa4b.dynamic.kabel-deutschland.de. [188.193.170.75]) by smtp.gmail.com with ESMTPSA id m10sm351993ejx.10.2021.03.10.13.55.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Mar 2021 13:55:38 -0800 (PST) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Wed, 10 Mar 2021 22:54:40 +0100 Message-Id: <20210310215446.1396386-8-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210310010601.1142819-1-andreas.rheinhardt@gmail.com> References: <20210310010601.1142819-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 17/23] dnn/dnn_backend_native_layer_conv2d: Fix memleak on error X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 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: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" If an error happens when preparing the output data buffer, an already allocated array would leak. Fix this by postponing its allocation. Also zero-allocate the allocated array for safety. Fixes Coverity issue #1473531. Signed-off-by: Andreas Rheinhardt --- libavfilter/dnn/dnn_backend_native_layer_conv2d.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libavfilter/dnn/dnn_backend_native_layer_conv2d.c b/libavfilter/dnn/dnn_backend_native_layer_conv2d.c index cdf65974b6..c2073a02de 100644 --- a/libavfilter/dnn/dnn_backend_native_layer_conv2d.c +++ b/libavfilter/dnn/dnn_backend_native_layer_conv2d.c @@ -191,7 +191,7 @@ int ff_dnn_execute_layer_conv2d(DnnOperand *operands, const int32_t *input_opera int thread_num = (ctx->options.conv2d_threads <= 0 || ctx->options.conv2d_threads > av_cpu_count()) ? (av_cpu_count() + 1) : (ctx->options.conv2d_threads); int thread_stride; - ThreadParam **thread_param = av_malloc_array(thread_num, sizeof(*thread_param)); + ThreadParam **thread_param; #else ThreadParam thread_param = { 0 }; #endif @@ -227,6 +227,7 @@ int ff_dnn_execute_layer_conv2d(DnnOperand *operands, const int32_t *input_opera thread_common_param.ctx = ctx; #if HAVE_PTHREAD_CANCEL + thread_param = av_calloc(thread_num, sizeof(*thread_param)); thread_stride = (height - pad_size * 2) / thread_num; //create threads for (int i = 0; i < thread_num; i++){