From patchwork Sun Dec 1 09:56:26 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 16504 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 48C604475CA for ; Sun, 1 Dec 2019 11:56:41 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 11A5468AEAB; Sun, 1 Dec 2019 11:56:41 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f67.google.com (mail-wr1-f67.google.com [209.85.221.67]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id C5D3C68A886 for ; Sun, 1 Dec 2019 11:56:34 +0200 (EET) Received: by mail-wr1-f67.google.com with SMTP id w15so9454731wru.4 for ; Sun, 01 Dec 2019 01:56:34 -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:mime-version :content-transfer-encoding; bh=PvjSUrpsFs90wlTw8orZdCjewgzCbEez7xxrBGs0H4o=; b=JE/OwICN6Crkcb7XaP5n/nokJb/lzYdKTFuCALa1FPflMNOqoc7NDoBt4i3mVqg76D vgVYXd9d11E8vNJ2eMJYZniiNV4tjS1FIKIDL5qryYslHn2iNA+7rnQuooiyh9seUREl 48INenrYdEdoYcNbWtqgbskFnROHnxdZT9wTPPFj5ocsNwUZv+t+yIxhjJT6MAQQamXj ugFP7gSu2rj+QJSENkgWaTz7JxQA3auhHt6DiImcWNcf3O27tqcMixCHAgYtkO9GIVkb UOVlUCY3VU0M9uT+TpJx8HcCJLB4FbsNzWKj+0kbaA67fW5OWFiltXSV5yMLkODsWxFn l3vw== 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:mime-version :content-transfer-encoding; bh=PvjSUrpsFs90wlTw8orZdCjewgzCbEez7xxrBGs0H4o=; b=uHOWMBOTm0WQ7Ili3oLpN/ZY3OV3kFbhCPtyY4GunJDrL8i5GdEDnHuZsLv/9eFADK atPqymNoTntGYkYRXKSNHPw9JLA6rYKsynpC6vDskf6sJ5zQoogPZpY1+fORYQRGPAdy B0W2GiqQO2lB2bk1f/TB7u9UVKp7f1j4rybkPpDWNHYJo1XkKAA3buqNYzjfJoLFmP2F HZ0zm9U/8gllM90aWKBtJmdzb5lFDK4eiyiqh4CuGcRJq3TtxfJfIZBWYUZ1fGO+XMIf ZOH0l7OL/P8ykduXtexwf7ZIqD1BmivXI85y6bK6DmepSHR5hq1sJb9S3kxRAFgw1yxQ t9pw== X-Gm-Message-State: APjAAAW74Va9fPab5vxYbCdpO7AN7UPRlmAUKQcb75MFL3/XGGlLO2oF KjL+sxgrVkB9WhN5xCL5baxh2k3i X-Google-Smtp-Source: APXvYqwH6RW4zkR59Gz3Pxe7bhHIMpHw3QrYMRJHklrSRPpfRWvCmZWU1o+NevQ0kRQcWZV2HbEd5g== X-Received: by 2002:adf:93c6:: with SMTP id 64mr3539335wrp.212.1575194194128; Sun, 01 Dec 2019 01:56:34 -0800 (PST) Received: from sblaptop.fritz.box (ipbcc08e23.dynamic.kabel-deutschland.de. [188.192.142.35]) by smtp.gmail.com with ESMTPSA id 91sm36259705wrm.42.2019.12.01.01.56.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 01 Dec 2019 01:56:33 -0800 (PST) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sun, 1 Dec 2019 10:56:26 +0100 Message-Id: <20191201095626.15871-1-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] avfilter/vf_unsharp: Don't dereference NULL 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" The unsharp filter uses an array of arrays of uint32_t, each of which is separately allocated. These arrays also need to freed separately; but before doing so, one needs to check whether the array of arrays has actually been allocated, otherwise one would dereference a NULL pointer. This fixes #8408. Furthermore, the array of arrays needs to be zero-initialized so that no uninitialized pointer will be freed in case an allocation of one of the individual arrays fails. Signed-off-by: Andreas Rheinhardt --- libavfilter/vf_unsharp.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/libavfilter/vf_unsharp.c b/libavfilter/vf_unsharp.c index 95b4968d41..7b430b650d 100644 --- a/libavfilter/vf_unsharp.c +++ b/libavfilter/vf_unsharp.c @@ -218,7 +218,7 @@ static int init_filter_param(AVFilterContext *ctx, UnsharpFilterParam *fp, const effect, effect_type, fp->msize_x, fp->msize_y, fp->amount / 65535.0); fp->sr = av_malloc_array((MAX_MATRIX_SIZE - 1) * s->nb_threads, sizeof(uint32_t)); - fp->sc = av_malloc_array(2 * fp->steps_y * s->nb_threads, sizeof(uint32_t **)); + fp->sc = av_mallocz_array(2 * fp->steps_y * s->nb_threads, sizeof(uint32_t *)); if (!fp->sr || !fp->sc) return AVERROR(ENOMEM); @@ -258,9 +258,11 @@ static void free_filter_param(UnsharpFilterParam *fp, int nb_threads) { int z; - for (z = 0; z < 2 * fp->steps_y * nb_threads; z++) - av_freep(&fp->sc[z]); - av_freep(&fp->sc); + if (fp->sc) { + for (z = 0; z < 2 * fp->steps_y * nb_threads; z++) + av_freep(&fp->sc[z]); + av_freep(&fp->sc); + } av_freep(&fp->sr); }