From patchwork Mon Jan 24 19:13:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Han-Wen Nienhuys X-Patchwork-Id: 12722865 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 02DABC4332F for ; Mon, 24 Jan 2022 19:39:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353343AbiAXTjA (ORCPT ); Mon, 24 Jan 2022 14:39:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51652 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352460AbiAXTab (ORCPT ); Mon, 24 Jan 2022 14:30:31 -0500 Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 241ECC02982F for ; Mon, 24 Jan 2022 11:13:53 -0800 (PST) Received: by mail-wr1-x430.google.com with SMTP id v13so15448942wrv.10 for ; Mon, 24 Jan 2022 11:13:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=BFxgNN28edqdOZ+Gb6YENsO0axQWrnuWxBbtDVaOk9s=; b=K7Ey1QshAj/m9etUkmYB4NnjIKRtkZq0o96gf5SXUQF6sDwsNRUj3YSaPzRi1F1rPP Z2Is8a8toeFUcqmnzdbPuFHDcKaTt6QQ6ZYxQFTi7GX0144Q1h08qWNhoBGfHKVa8mu/ g36dIBVbl6qkuRU8pS1vG3wPM/bvUotUhBKb1dXsNFXMxDu/IRz5rfaDmn0BhL2vkY8k YjjYn+mXgSxg1hZ9Dz1SNUUnURKFavQjA+anjKB8kNQWKZfo4wzeC7doo4Etg/n6HNtA wtDqAEfREs8J9113h27lsCMlKTkREBe92fLM+Pu9s1GP429hHAFBkydMCqhLkwsZqLlw JAxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=BFxgNN28edqdOZ+Gb6YENsO0axQWrnuWxBbtDVaOk9s=; b=EqMdsIUsIRYgkYN1Smw0s5e+dfQoez2dU4TwZhDiwKEeNQpEJyk8EbFgN7bm8I62we QL+Gv7u/18EDlIYL25YfcjzbYyL+yvFFOdfatUtR82ShzV/FRL0GbOebLXdPVcQZTu3w E5gvfkRweo7Bafe6H4AuCESjkceSbaBEgLP/Lm7ri7jJ1fjRy0yqbIzydnlIc+awZO0+ Shi0pMJ7NEiYcQqLENKdMSCB/IB84/iXP5546JqlnCYeHi2D8CqxCTlIzrXcjs2FseQp 6+SMBGlO5VV9lsaWngvLD2fE1Zv2a94/jwiDb3gFdmj3qHwWA35lFB5cz9p3R6xSCLEu 9ldA== X-Gm-Message-State: AOAM530H1p3YNnkbTKCegcRaBGs6GEYnQ2+Tfjbz7QA+9xSZ0aL0BUMF BF7/3ZCtdKByg5HPyf2nh8qE2/IwyJP5vQ== X-Google-Smtp-Source: ABdhPJxWbbN+8cmlrk1892jJxmrEs9PMHFxtNuVqfyFIG6u5wl0JZ5ioOsNZwmmf5FLMbKEZkKONLA== X-Received: by 2002:a05:6000:144c:: with SMTP id v12mr15525636wrx.218.1643051631604; Mon, 24 Jan 2022 11:13:51 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id v5sm18710259wrx.114.2022.01.24.11.13.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Jan 2022 11:13:51 -0800 (PST) Message-Id: In-Reply-To: References: Date: Mon, 24 Jan 2022 19:13:35 +0000 Subject: [PATCH v7 07/16] reftable: all xxx_free() functions accept NULL arguments Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Jeff King , Han-Wen Nienhuys , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason , =?utf-8?b?UmVuw6k=?= Scharfe , "brian m. carlson" , Johannes Schindelin , Neeraj Singh , Han-Wen Nienhuys , Han-Wen Nienhuys Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Han-Wen Nienhuys From: Han-Wen Nienhuys This fixes NULL derefs in error paths. Spotted by Coverity. Signed-off-by: Han-Wen Nienhuys --- reftable/reader.c | 2 ++ reftable/writer.c | 2 ++ 2 files changed, 4 insertions(+) diff --git a/reftable/reader.c b/reftable/reader.c index 35781593a29..272378ed1d5 100644 --- a/reftable/reader.c +++ b/reftable/reader.c @@ -646,6 +646,8 @@ int reftable_new_reader(struct reftable_reader **p, void reftable_reader_free(struct reftable_reader *r) { + if (!r) + return; reader_close(r); reftable_free(r); } diff --git a/reftable/writer.c b/reftable/writer.c index 35c8649c9b7..83a23daf60b 100644 --- a/reftable/writer.c +++ b/reftable/writer.c @@ -150,6 +150,8 @@ void reftable_writer_set_limits(struct reftable_writer *w, uint64_t min, void reftable_writer_free(struct reftable_writer *w) { + if (!w) + return; reftable_free(w->block); reftable_free(w); }