[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Bug-tar] [PATCH] maint: remove now-useless test-before-free
From: |
Jim Meyering |
Subject: |
[Bug-tar] [PATCH] maint: remove now-useless test-before-free |
Date: |
Fri, 07 Jan 2011 12:44:13 +0100 |
Hi,
I happened to notice one of these, and ran the following
command (from comments of the gnulib script) to fix the rest:
git grep -l -z "$free *(" \
| xargs -0 /gnulib/build-aux/useless-if-before-free -l \
| xargs -0 perl -0x3b -pi -e
's/\bif\s*\(\s*(\S+?)(?:\s*!=\s*(?:0|NULL))?\s*\)\s+('"$free"'\s*\((?:\s*\([^)]+\))?\s*\1\s*\))/$2/s'
>From 7d6b79464e8077b5fcdcaf61c08b5f46be887402 Mon Sep 17 00:00:00 2001
From: Jim Meyering <address@hidden>
Date: Fri, 7 Jan 2011 12:40:06 +0100
Subject: [PATCH] maint: remove now-useless test-before-free
There is no longer (since SunOS 4) any need to guard against
free (NULL), so replace each "if (p) free (p);" with "free (p);".
* src/incremen.c (scan_directory, read_directory_file): As above.
(try_purge_directory): Likewise.
* src/list.c (read_header): Likewise.
* src/misc.c (assign_string): Likewise.
---
src/incremen.c | 9 +++------
src/list.c | 12 ++++--------
src/misc.c | 3 +--
3 files changed, 8 insertions(+), 16 deletions(-)
diff --git a/src/incremen.c b/src/incremen.c
index 2b33c5d..b2ab5bf 100644
--- a/src/incremen.c
+++ b/src/incremen.c
@@ -779,8 +779,7 @@ scan_directory (struct tar_stat_info *st)
namebuf_free (nbuf);
- if (dirp)
- free (dirp);
+ free (dirp);
return directory;
}
@@ -1348,8 +1347,7 @@ read_directory_file (void)
if (ferror (listed_incremental_stream))
read_error (listed_incremental_option);
- if (buf)
- free (buf);
+ free (buf);
}
/* Output incremental data for the directory ENTRY to the file DATA.
@@ -1660,8 +1658,7 @@ try_purge_directory (char const *directory_name)
{
const char *entry;
struct stat st;
- if (p)
- free (p);
+ free (p);
p = new_name (directory_name, cur);
if (deref_stat (p, &st) != 0)
diff --git a/src/list.c b/src/list.c
index a70f0d3..cf2de09 100644
--- a/src/list.c
+++ b/src/list.c
@@ -433,15 +433,13 @@ read_header (union block **return_block, struct
tar_stat_info *info,
if (header->header.typeflag == GNUTYPE_LONGNAME)
{
- if (next_long_name)
- free (next_long_name);
+ free (next_long_name);
next_long_name = header_copy;
next_long_name_blocks = size / BLOCKSIZE;
}
else
{
- if (next_long_link)
- free (next_long_link);
+ free (next_long_link);
next_long_link = header_copy;
next_long_link_blocks = size / BLOCKSIZE;
}
@@ -500,8 +498,7 @@ read_header (union block **return_block, struct
tar_stat_info *info,
struct posix_header const *h = &header->header;
char namebuf[sizeof h->prefix + 1 + NAME_FIELD_SIZE + 1];
- if (recent_long_name)
- free (recent_long_name);
+ free (recent_long_name);
if (next_long_name)
{
@@ -532,8 +529,7 @@ read_header (union block **return_block, struct
tar_stat_info *info,
assign_string (&info->file_name, name);
info->had_trailing_slash = strip_trailing_slashes (info->file_name);
- if (recent_long_link)
- free (recent_long_link);
+ free (recent_long_link);
if (next_long_link)
{
diff --git a/src/misc.c b/src/misc.c
index adc9298..b75f2ab 100644
--- a/src/misc.c
+++ b/src/misc.c
@@ -37,8 +37,7 @@
void
assign_string (char **string, const char *value)
{
- if (*string)
- free (*string);
+ free (*string);
*string = value ? xstrdup (value) : 0;
}
--
1.7.3.5
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Bug-tar] [PATCH] maint: remove now-useless test-before-free,
Jim Meyering <=