This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [PATCH] remove useless if-before-free tests, take 2
- From: Jim Meyering <jim at meyering dot net>
- To: "GNU C. Library" <libc-alpha at sourceware dot org>
- Date: Mon, 26 May 2008 22:43:36 +0200
- Subject: Re: [PATCH] remove useless if-before-free tests, take 2
- References: <87iqx28e0s.fsf@rho.meyering.net>
Jim Meyering <jim@meyering.net> wrote:
> [hmm... I would have replied to the original, but it hasn't reached the
> list yet. That's due to the pesky new moderation delay, I suppose. ]
>
> This removes one more (in posix/glob.c) that was not caught initially
> due to the embedded white spaces in the expressions:
>
> - if (pglob->gl_pathv[pglob->gl_offs + i] != NULL)
> - free (pglob->gl_pathv[pglob->gl_offs + i]);
> + free (pglob->gl_pathv[pglob->gl_offs + i]);
>
> This patch also updates the copyright year numbers that needed it.
Finally, here are ChangeLog entries, too:
(template automatically generated with vc-chlog)
2008-05-26 Jim Meyering <meyering@redhat.com>
Remove useless more "if" tests before "free".
* include/inline-hashtab.h (htab_delete): Likewise.
* libio/freopen.c (freopen): Likewise.
* libio/freopen64.c (freopen64): Likewise.
* locale/programs/ld-collate.c (collate_read): Likewise.
* misc/fstab.c (libc_freeres_fn): Likewise.
* posix/glob.c (libc_hidden_def): Likewise.
---
include/inline-hashtab.h | 3 +--
libio/freopen.c | 5 ++---
libio/freopen64.c | 5 ++---
locale/programs/ld-collate.c | 12 ++++--------
misc/fstab.c | 6 +++---
posix/glob.c | 5 ++---
6 files changed, 14 insertions(+), 22 deletions(-)
diff --git a/include/inline-hashtab.h b/include/inline-hashtab.h
index ad361cd..c359161 100644
--- a/include/inline-hashtab.h
+++ b/include/inline-hashtab.h
@@ -142,8 +142,7 @@ htab_delete (struct hashtab *htab)
int i;
for (i = htab->size - 1; i >= 0; i--)
- if (htab->entries[i])
- free (htab->entries[i]);
+ free (htab->entries[i]);
if (htab->free)
htab->free (htab->entries);
diff --git a/libio/freopen.c b/libio/freopen.c
index d94a562..d80815f 100644
--- a/libio/freopen.c
+++ b/libio/freopen.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1993,95,96,97,98,2000,2001,2002,2003
+/* Copyright (C) 1993,95,96,97,98,2000,2001,2002,2003,2008
Free Software Foundation, Inc.
This file is part of the GNU C Library.
@@ -80,8 +80,7 @@ freopen (filename, mode, fp)
if (fd != -1)
{
__close (fd);
- if (filename != NULL)
- free ((char *) filename);
+ free ((char *) filename);
}
_IO_release_lock (fp);
return result;
diff --git a/libio/freopen64.c b/libio/freopen64.c
index f8da78c..2dad6d7 100644
--- a/libio/freopen64.c
+++ b/libio/freopen64.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1993,1995,1996,1997,1998,2000,2001,2002, 2003
+/* Copyright (C) 1993,1995,1996,1997,1998,2000,2001,2002, 2003, 2008
Free Software Foundation, Inc.
This file is part of the GNU C Library.
@@ -64,8 +64,7 @@ freopen64 (filename, mode, fp)
if (fd != -1)
{
__close (fd);
- if (filename != NULL)
- free ((char *) filename);
+ free ((char *) filename);
}
_IO_release_lock (fp);
return result;
diff --git a/locale/programs/ld-collate.c b/locale/programs/ld-collate.c
index 7af3b8a..bf50e77 100644
--- a/locale/programs/ld-collate.c
+++ b/locale/programs/ld-collate.c
@@ -2961,8 +2961,7 @@ collate_read (struct linereader *ldfile, struct localedef_t *result,
else
{
col_elem_free:
- if (symbol != NULL)
- free ((char *) symbol);
+ free ((char *) symbol);
free (arg->val.str.startmb);
free (arg->val.str.startwc);
}
@@ -3142,8 +3141,7 @@ collate_read (struct linereader *ldfile, struct localedef_t *result,
arg = lr_token (ldfile, charmap, result, repertoire, verbose);
if (arg->tok != tok_bsymbol)
{
- if (newname != NULL)
- free ((char *) newname);
+ free ((char *) newname);
goto err_label;
}
@@ -3157,10 +3155,8 @@ collate_read (struct linereader *ldfile, struct localedef_t *result,
"LC_COLLATE");
sym_equiv_free:
- if (newname != NULL)
- free ((char *) newname);
- if (symname != NULL)
- free ((char *) symname);
+ free ((char *) newname);
+ free ((char *) symname);
break;
}
if (symname == NULL)
diff --git a/misc/fstab.c b/misc/fstab.c
index b434203..ab5581e 100644
--- a/misc/fstab.c
+++ b/misc/fstab.c
@@ -1,4 +1,5 @@
-/* Copyright (C) 1995, 1996, 1997, 1998, 2000 Free Software Foundation, Inc.
+/* Copyright (C) 1995, 1996, 1997, 1998, 2000, 2008
+ Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
@@ -185,6 +186,5 @@ libc_freeres_fn (fstab_free)
char *buffer;
buffer = fstab_state.fs_buffer;
- if (buffer != NULL)
- free ((void *) buffer);
+ free ((void *) buffer);
}
diff --git a/posix/glob.c b/posix/glob.c
index b7d9617..73081ec 100644
--- a/posix/glob.c
+++ b/posix/glob.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1991-2002, 2003, 2004, 2005, 2006, 2007
+/* Copyright (C) 1991-2002, 2003, 2004, 2005, 2006, 2007, 2008
Free Software Foundation, Inc.
This file is part of the GNU C Library.
@@ -1075,8 +1075,7 @@ globfree (pglob)
{
size_t i;
for (i = 0; i < pglob->gl_pathc; ++i)
- if (pglob->gl_pathv[pglob->gl_offs + i] != NULL)
- free (pglob->gl_pathv[pglob->gl_offs + i]);
+ free (pglob->gl_pathv[pglob->gl_offs + i]);
free (pglob->gl_pathv);
pglob->gl_pathv = NULL;
}
--
1.5.5.1.383.g8078b