From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from barracuda.ebox.ca (barracuda.ebox.ca [96.127.255.19]) by sourceware.org (Postfix) with ESMTPS id A75DB383E800 for ; Thu, 21 May 2020 15:10:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org A75DB383E800 X-ASG-Debug-ID: 1590073833-0c856e314b9c5d80001-fS2M51 Received: from smtp.ebox.ca (smtp.ebox.ca [96.127.255.82]) by barracuda.ebox.ca with ESMTP id fFGaHL9nMFNw0clK (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Thu, 21 May 2020 11:10:33 -0400 (EDT) X-Barracuda-Envelope-From: simon.marchi@efficios.com X-Barracuda-RBL-Trusted-Forwarder: 96.127.255.82 Received: from smarchi-efficios.internal.efficios.com (192-222-181-218.qc.cable.ebox.net [192.222.181.218]) by smtp.ebox.ca (Postfix) with ESMTP id 4EC09441D64; Thu, 21 May 2020 11:10:33 -0400 (EDT) From: Simon Marchi X-Barracuda-Effective-Source-IP: 192-222-181-218.qc.cable.ebox.net[192.222.181.218] X-Barracuda-Apparent-Source-IP: 192.222.181.218 X-Barracuda-RBL-IP: 192.222.181.218 To: gdb-patches@sourceware.org Cc: Simon Marchi Subject: [PATCH] gdb: remove unnecessary NULL checks before xfree Date: Thu, 21 May 2020 11:10:32 -0400 X-ASG-Orig-Subj: [PATCH] gdb: remove unnecessary NULL checks before xfree Message-Id: <20200521151032.3116197-1-simon.marchi@efficios.com> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Barracuda-Connect: smtp.ebox.ca[96.127.255.82] X-Barracuda-Start-Time: 1590073833 X-Barracuda-Encrypted: DHE-RSA-AES256-SHA X-Barracuda-URL: https://96.127.255.19:443/cgi-mod/mark.cgi X-Barracuda-Scan-Msg-Size: 5700 X-Virus-Scanned: by bsmtpd at ebox.ca X-Barracuda-BRTS-Status: 1 X-Barracuda-Spam-Score: 0.00 X-Barracuda-Spam-Status: No, SCORE=0.00 using global scores of TAG_LEVEL=1000.0 QUARANTINE_LEVEL=1000.0 KILL_LEVEL=8.0 tests= X-Barracuda-Spam-Report: Code version 3.2, rules version 3.2.3.82004 Rule breakdown below pts rule name description ---- ---------------------- -------------------------------------------------- X-Spam-Status: No, score=-26.4 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_NONE, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_SOFTFAIL, 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 15:10:37 -0000 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. gdb/ChangeLog: * coffread.c (patch_type): Remove NULL check before xfree. * corefile.c (set_gnutarget): Likewise. * cp-abi.c (set_cp_abi_as_auto_default): Likewise. * exec.c (build_section_table): Likewise. * remote.c (remote_target::pass_signals): Likewise. * utils.c (n_spaces): Likewise. * cli/cli-script.c (document_command): Likewise. * i386-windows-tdep.c (core_process_module_section): Likewise. * linux-fork.c (struct fork_info) <~fork_info>: Likewise. --- gdb/cli/cli-script.c | 3 +-- gdb/coffread.c | 3 +-- gdb/corefile.c | 3 +-- gdb/cp-abi.c | 6 ++---- gdb/exec.c | 3 +-- gdb/i386-windows-tdep.c | 3 +-- gdb/linux-fork.c | 4 ++-- gdb/remote.c | 3 +-- gdb/symfile.c | 3 +-- gdb/utils.c | 3 +-- 10 files changed, 12 insertions(+), 22 deletions(-) diff --git a/gdb/cli/cli-script.c b/gdb/cli/cli-script.c index c9d23789068d..90ee67a5f3d3 100644 --- a/gdb/cli/cli-script.c +++ b/gdb/cli/cli-script.c @@ -1528,8 +1528,7 @@ document_command (const char *comname, int from_tty) counted_command_line doclines = read_command_lines (prompt.c_str (), from_tty, 0, 0); - if (c->doc) - xfree ((char *) c->doc); + xfree ((char *) c->doc); { struct command_line *cl1; diff --git a/gdb/coffread.c b/gdb/coffread.c index fc44e53cc4c4..0f7a6e3e5ad0 100644 --- a/gdb/coffread.c +++ b/gdb/coffread.c @@ -1467,8 +1467,7 @@ patch_type (struct type *type, struct type *real_type) { /* The previous copy of TYPE_NAME is allocated by process_coff_symbol. */ - if (target->name ()) - xfree ((char*) target->name ()); + xfree ((char *) target->name ()); target->set_name (xstrdup (real_target->name ())); } } diff --git a/gdb/corefile.c b/gdb/corefile.c index 4ce1bb78f282..996e5301b27a 100644 --- a/gdb/corefile.c +++ b/gdb/corefile.c @@ -472,8 +472,7 @@ complete_set_gnutarget (struct cmd_list_element *cmd, void set_gnutarget (const char *newtarget) { - if (gnutarget_string != NULL) - xfree (gnutarget_string); + xfree (gnutarget_string); gnutarget_string = xstrdup (newtarget); set_gnutarget_command (NULL, 0, NULL); } diff --git a/gdb/cp-abi.c b/gdb/cp-abi.c index 6997a7bdbe9b..3e2edad45ca3 100644 --- a/gdb/cp-abi.c +++ b/gdb/cp-abi.c @@ -273,10 +273,8 @@ set_cp_abi_as_auto_default (const char *short_name) _("Cannot find C++ ABI \"%s\" to set it as auto default."), short_name); - if (auto_cp_abi.longname != NULL) - xfree ((char *) auto_cp_abi.longname); - if (auto_cp_abi.doc != NULL) - xfree ((char *) auto_cp_abi.doc); + xfree ((char *) auto_cp_abi.longname); + xfree ((char *) auto_cp_abi.doc); auto_cp_abi = *abi; diff --git a/gdb/exec.c b/gdb/exec.c index 93dd157e583e..14c77495a38f 100644 --- a/gdb/exec.c +++ b/gdb/exec.c @@ -648,8 +648,7 @@ build_section_table (struct bfd *some_bfd, struct target_section **start, unsigned count; count = bfd_count_sections (some_bfd); - if (*start) - xfree (* start); + xfree (*start); *start = XNEWVEC (struct target_section, count); *end = *start; bfd_map_over_sections (some_bfd, add_to_section_table, (char *) end); diff --git a/gdb/i386-windows-tdep.c b/gdb/i386-windows-tdep.c index 7233b1f28f51..f5965399abce 100644 --- a/gdb/i386-windows-tdep.c +++ b/gdb/i386-windows-tdep.c @@ -142,8 +142,7 @@ core_process_module_section (bfd *abfd, asection *sect, void *obj) data->module_count++; out: - if (buf) - xfree (buf); + xfree (buf); return; } diff --git a/gdb/linux-fork.c b/gdb/linux-fork.c index 2233d4429ce0..e232d9c263a2 100644 --- a/gdb/linux-fork.c +++ b/gdb/linux-fork.c @@ -61,8 +61,8 @@ struct fork_info if (savedregs) delete savedregs; - if (filepos) - xfree (filepos); + + xfree (filepos); } ptid_t ptid = null_ptid; diff --git a/gdb/remote.c b/gdb/remote.c index 312a03c8fb42..c73eb6e9e136 100644 --- a/gdb/remote.c +++ b/gdb/remote.c @@ -2615,8 +2615,7 @@ remote_target::pass_signals (gdb::array_view pass_signals) putpkt (pass_packet); getpkt (&rs->buf, 0); packet_ok (rs->buf, &remote_protocol_packets[PACKET_QPassSignals]); - if (rs->last_pass_packet) - xfree (rs->last_pass_packet); + xfree (rs->last_pass_packet); rs->last_pass_packet = pass_packet; } else diff --git a/gdb/symfile.c b/gdb/symfile.c index b02a9235663b..b29f864b3735 100644 --- a/gdb/symfile.c +++ b/gdb/symfile.c @@ -3404,8 +3404,7 @@ enum ovly_index static void simple_free_overlay_table (void) { - if (cache_ovly_table) - xfree (cache_ovly_table); + xfree (cache_ovly_table); cache_novlys = 0; cache_ovly_table = NULL; cache_ovly_table_base = 0; diff --git a/gdb/utils.c b/gdb/utils.c index 989b13d0e0f3..d2290c30a78b 100644 --- a/gdb/utils.c +++ b/gdb/utils.c @@ -2260,8 +2260,7 @@ n_spaces (int n) if (n > max_spaces) { - if (spaces) - xfree (spaces); + xfree (spaces); spaces = (char *) xmalloc (n + 1); for (t = spaces + n; t != spaces;) *--t = ' '; -- 2.26.2