From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) by sourceware.org (Postfix) with ESMTP id 150D93840C3E for ; Thu, 21 May 2020 16:59:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 150D93840C3E Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-262-YVMCNAOgNGW5PZ0hJuNMcg-1; Thu, 21 May 2020 12:59:17 -0400 X-MC-Unique: YVMCNAOgNGW5PZ0hJuNMcg-1 Received: by mail-wr1-f72.google.com with SMTP id q13so3175420wrn.14 for ; Thu, 21 May 2020 09:59:17 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=jy2kbYWK++O1hB/LaYeGBz9FXaKQIm2Zx03/UYdVafQ=; b=GALHB9xEFpWJsFUnbnw6LGkcwGd4VQCyy6Blg3TnncyljBV+BW9LE6Frzr2HUcyatI R6A4DA4dhNMHw3r/v7dsOiGpKfyshdTE9kGB9ohN7Z+yThqHCZkE1WrrPS26+oUcQEZS aarDT8suCqi62Q/qTKotflVCyO/26s/y15hEVdaHel9Ezet/qAfU0x+kB0K7Jd5k50fh ClCsSc6GtDPy9FQMHAkmFy65hdSzk9sD7CkGNtCuXJeSI4marTT/zCA+glm5l1912Sw5 hN05DmKU8ab/cuwi9VA5KAuFPcXrJqnNztC4+N9BlAjJJLgfWs5Uzdm+s3jfjjbzYgob BegQ== X-Gm-Message-State: AOAM53077AzUUZwhx8/sXJInSNDiOblVxJlsz6N3wVV+w4mjcypHTj5u lq8LmQl0QnR4OWoJHas3GCzJ//JcvD8aXAe2MwK0l4M6ihxsCQatOxmnwvRa6sOiDqGZZkdqIyF lCjNHGEdVquWZtfuQXXeSQQ== X-Received: by 2002:a7b:c40f:: with SMTP id k15mr10401618wmi.65.1590080356121; Thu, 21 May 2020 09:59:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzrK8/kyDngov1dVBEiiOvSvXFTYLW1yjd/bJ/LrTmkoSAqFGzjeiOkvSq/YIYB9ymI5LVSxQ== X-Received: by 2002:a7b:c40f:: with SMTP id k15mr10401601wmi.65.1590080355907; Thu, 21 May 2020 09:59:15 -0700 (PDT) Received: from ?IPv6:2001:8a0:f909:7b00:2327:23ca:3e56:ef5f? ([2001:8a0:f909:7b00:2327:23ca:3e56:ef5f]) by smtp.gmail.com with ESMTPSA id m1sm7454738wrx.44.2020.05.21.09.59.15 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 21 May 2020 09:59:15 -0700 (PDT) Subject: Re: [PATCH] gdb: remove unnecessary NULL checks before xfree To: Simon Marchi , gdb-patches@sourceware.org References: <20200521151032.3116197-1-simon.marchi@efficios.com> From: Pedro Alves Message-ID: <9267cb3e-36ae-5d05-d636-37ef2d177190@redhat.com> Date: Thu, 21 May 2020 17:59:14 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.2.1 MIME-Version: 1.0 In-Reply-To: <20200521151032.3116197-1-simon.marchi@efficios.com> Content-Language: en-US X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-7.8 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 21 May 2020 16:59:23 -0000 On 5/21/20 4:10 PM, Simon Marchi via Gdb-patches wrote: > I was inspired by a series of patches merged by Alan Modra in the other > projects, so I did the same in GDB with a bit of Coccinelle and grep. > > This patch removes the unnecessary NULL checks before calls to xfree. > They are unnecessary because xfree already does a NULL check. Since > free is supposed to handle NULL values correctly, the NULL check in > xfree itself is also questionable, but I've left it there for now. xfree was invented exactly because some ancient hosts did not handle free(NULL) gracefully: https://sourceware.org/legacy-ml/gdb/2000-11/msg00276.html I'd like to believe that such hosts are long gone. (It's a reasonable micro-optimization to check for NULL before calling free, to avoid the function call overhead, but I don't think this is the motivation for any of the cases here. Since xfree is inline, I guess we're applying that micro-optimization everywhere, by chance.) Thanks, Pedro Alves