changeset 9749:daf5ba9fe2d9

Remove useless "if" tests before free. Deprecate "free" module. * doc/posix-functions/free.texi: Mention that this module is no longer useful. * modules/free (Notice): Say this module is obsolete. * modules/readutmp (Depends-on): Remove free. * lib/save-cwd.c (free_cwd): Remove useless "if" before free. * lib/putenv.c (putenv): Likewise. * lib/gc-gnulib.c (gc_cipher_close): Likewise. * lib/getaddrinfo.c (freeaddrinfo): Likewise. * tests/test-c-strcasestr.c (main): Likewise. * tests/test-c-strstr.c (main): Likewise. * tests/test-mbscasestr1.c (main): Likewise. * tests/test-mbscasestr2.c (main): Likewise. * tests/test-mbsstr1.c (main): Likewise. * tests/test-mbsstr2.c (main): Likewise. * tests/test-memmem.c (main): Likewise. * tests/test-strcasestr.c (main): Likewise. * tests/test-striconv.c (main): Likewise. * tests/test-striconveh.c (main): Likewise. * tests/test-striconveha.c (main): Likewise. * tests/test-strstr.c (main): Likewise.
author Jim Meyering <meyering@redhat.com>
date Mon, 18 Feb 2008 14:12:07 +0100
parents c0c8409cb7a2
children 98643d71bad2
files ChangeLog doc/posix-functions/free.texi lib/gc-gnulib.c lib/getaddrinfo.c lib/putenv.c lib/save-cwd.c modules/free modules/readutmp tests/test-c-strcasestr.c tests/test-c-strstr.c tests/test-mbscasestr1.c tests/test-mbscasestr2.c tests/test-mbsstr1.c tests/test-mbsstr2.c tests/test-memmem.c tests/test-strcasestr.c tests/test-striconv.c tests/test-striconveh.c tests/test-striconveha.c tests/test-strstr.c
diffstat 20 files changed, 58 insertions(+), 59 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Sun Mar 02 17:19:20 2008 +0100
+++ b/ChangeLog	Mon Feb 18 14:12:07 2008 +0100
@@ -1,5 +1,27 @@
 2008-03-02  Jim Meyering  <meyering@redhat.com>
 
+	Remove useless "if" tests before free.  Deprecate "free" module.
+	* doc/posix-functions/free.texi: Mention that this
+	module is no longer useful.
+	* modules/free (Notice): Say this module is obsolete.
+	* modules/readutmp (Depends-on): Remove free.
+	* lib/save-cwd.c (free_cwd): Remove useless "if" before free.
+	* lib/putenv.c (putenv): Likewise.
+	* lib/gc-gnulib.c (gc_cipher_close): Likewise.
+	* lib/getaddrinfo.c (freeaddrinfo): Likewise.
+	* tests/test-c-strcasestr.c (main): Likewise.
+	* tests/test-c-strstr.c (main): Likewise.
+	* tests/test-mbscasestr1.c (main): Likewise.
+	* tests/test-mbscasestr2.c (main): Likewise.
+	* tests/test-mbsstr1.c (main): Likewise.
+	* tests/test-mbsstr2.c (main): Likewise.
+	* tests/test-memmem.c (main): Likewise.
+	* tests/test-strcasestr.c (main): Likewise.
+	* tests/test-striconv.c (main): Likewise.
+	* tests/test-striconveh.c (main): Likewise.
+	* tests/test-striconveha.c (main): Likewise.
+	* tests/test-strstr.c (main): Likewise.
+
 	* build-aux/git-version-gen: Adjust a comment and the Usage string.
 
 	bootstrap: sync from coreutils again
--- a/doc/posix-functions/free.texi	Sun Mar 02 17:19:20 2008 +0100
+++ b/doc/posix-functions/free.texi	Mon Feb 18 14:12:07 2008 +0100
@@ -9,7 +9,10 @@
 Portability problems fixed by Gnulib:
 @itemize
 @item
-On old platforms, @code{free (NULL)} is not allowed.
+On old platforms such as SunOS4, @code{free (NULL)} fails.
+However, since all such systems are so old as to no longer
+be considered ``reasonable portability targets,''
+this module is no longer useful.
 @end itemize
 
 Portability problems not fixed by Gnulib:
--- a/lib/gc-gnulib.c	Sun Mar 02 17:19:20 2008 +0100
+++ b/lib/gc-gnulib.c	Mon Feb 18 14:12:07 2008 +0100
@@ -546,8 +546,7 @@
 {
   _gc_cipher_ctx *ctx = handle;
 
-  if (ctx)
-    free (ctx);
+  free (ctx);
 
   return GC_OK;
 }
--- a/lib/getaddrinfo.c	Sun Mar 02 17:19:20 2008 +0100
+++ b/lib/getaddrinfo.c	Mon Feb 18 14:12:07 2008 +0100
@@ -326,7 +326,7 @@
       cur = ai;
       ai = ai->ai_next;
 
-      if (cur->ai_canonname) free (cur->ai_canonname);
+      free (cur->ai_canonname);
       free (cur);
     }
 }
--- a/lib/putenv.c	Sun Mar 02 17:19:20 2008 +0100
+++ b/lib/putenv.c	Mon Feb 18 14:12:07 2008 +0100
@@ -1,4 +1,4 @@
-/* Copyright (C) 1991, 1994, 1997, 1998, 2000, 2003, 2004, 2005, 2006, 2007
+/* Copyright (C) 1991, 1994, 1997-1998, 2000, 2003-2008
    Free Software Foundation, Inc.
 
    NOTE: The canonical source of this file is maintained with the GNU C
@@ -122,8 +122,7 @@
 		     size * sizeof (char *));
       new_environ[size] = (char *) string;
       new_environ[size + 1] = NULL;
-      if (last_environ != NULL)
-	free (last_environ);
+      free (last_environ);
       last_environ = new_environ;
       environ = new_environ;
     }
--- a/lib/save-cwd.c	Sun Mar 02 17:19:20 2008 +0100
+++ b/lib/save-cwd.c	Mon Feb 18 14:12:07 2008 +0100
@@ -97,6 +97,5 @@
 {
   if (cwd->desc >= 0)
     close (cwd->desc);
-  if (cwd->name)
-    free (cwd->name);
+  free (cwd->name);
 }
--- a/modules/free	Sun Mar 02 17:19:20 2008 +0100
+++ b/modules/free	Mon Feb 18 14:12:07 2008 +0100
@@ -1,6 +1,9 @@
 Description:
 Work around incompatibility on older systems where free (NULL) fails.
 
+Notice:
+This module is obsolete.
+
 Files:
 lib/free.c
 m4/free.m4
@@ -20,4 +23,3 @@
 
 Maintainer:
 Paul Eggert
-
--- a/modules/readutmp	Sun Mar 02 17:19:20 2008 +0100
+++ b/modules/readutmp	Mon Feb 18 14:12:07 2008 +0100
@@ -9,7 +9,6 @@
 Depends-on:
 extensions
 xalloc
-free
 stdbool
 
 configure.ac:
--- a/tests/test-c-strcasestr.c	Sun Mar 02 17:19:20 2008 +0100
+++ b/tests/test-c-strcasestr.c	Mon Feb 18 14:12:07 2008 +0100
@@ -136,10 +136,8 @@
 	result = c_strcasestr (haystack, needle);
 	ASSERT (result == haystack + m);
       }
-    if (needle != NULL)
-      free (needle);
-    if (haystack != NULL)
-      free (haystack);
+    free (needle);
+    free (haystack);
   }
 
   return 0;
--- a/tests/test-c-strstr.c	Sun Mar 02 17:19:20 2008 +0100
+++ b/tests/test-c-strstr.c	Mon Feb 18 14:12:07 2008 +0100
@@ -129,10 +129,8 @@
 	result = c_strstr (haystack, needle);
 	ASSERT (result == haystack + m);
       }
-    if (needle != NULL)
-      free (needle);
-    if (haystack != NULL)
-      free (haystack);
+    free (needle);
+    free (haystack);
   }
 
   return 0;
--- a/tests/test-mbscasestr1.c	Sun Mar 02 17:19:20 2008 +0100
+++ b/tests/test-mbscasestr1.c	Mon Feb 18 14:12:07 2008 +0100
@@ -131,10 +131,8 @@
 	result = mbscasestr (haystack, needle);
 	ASSERT (result == haystack + m);
       }
-    if (needle != NULL)
-      free (needle);
-    if (haystack != NULL)
-      free (haystack);
+    free (needle);
+    free (haystack);
   }
 
   return 0;
--- a/tests/test-mbscasestr2.c	Sun Mar 02 17:19:20 2008 +0100
+++ b/tests/test-mbscasestr2.c	Mon Feb 18 14:12:07 2008 +0100
@@ -143,10 +143,8 @@
 	result = mbscasestr (haystack, needle);
 	ASSERT (result == haystack + m);
       }
-    if (needle != NULL)
-      free (needle);
-    if (haystack != NULL)
-      free (haystack);
+    free (needle);
+    free (haystack);
   }
 
   return 0;
--- a/tests/test-mbsstr1.c	Sun Mar 02 17:19:20 2008 +0100
+++ b/tests/test-mbsstr1.c	Mon Feb 18 14:12:07 2008 +0100
@@ -130,10 +130,8 @@
 	result = mbsstr (haystack, needle);
 	ASSERT (result == haystack + m);
       }
-    if (needle != NULL)
-      free (needle);
-    if (haystack != NULL)
-      free (haystack);
+    free (needle);
+    free (haystack);
   }
 
   return 0;
--- a/tests/test-mbsstr2.c	Sun Mar 02 17:19:20 2008 +0100
+++ b/tests/test-mbsstr2.c	Mon Feb 18 14:12:07 2008 +0100
@@ -143,10 +143,8 @@
 	result = mbsstr (haystack, needle);
 	ASSERT (result == haystack + m);
       }
-    if (needle != NULL)
-      free (needle);
-    if (haystack != NULL)
-      free (haystack);
+    free (needle);
+    free (haystack);
   }
 
   return 0;
--- a/tests/test-memmem.c	Sun Mar 02 17:19:20 2008 +0100
+++ b/tests/test-memmem.c	Mon Feb 18 14:12:07 2008 +0100
@@ -152,10 +152,8 @@
 	result = memmem (haystack, 2 * m + 1, needle, m + 1);
 	ASSERT (result == haystack + m);
       }
-    if (needle != NULL)
-      free (needle);
-    if (haystack != NULL)
-      free (haystack);
+    free (needle);
+    free (haystack);
   }
 
   /* Check that long needles not present in a haystack can be handled
@@ -179,10 +177,8 @@
 	    ASSERT (result == NULL);
 	  }
       }
-    if (haystack != NULL)
-      free (haystack);
-    if (needle != NULL)
-      free (needle);
+    free (haystack);
+    free (needle);
   }
 
   return 0;
--- a/tests/test-strcasestr.c	Sun Mar 02 17:19:20 2008 +0100
+++ b/tests/test-strcasestr.c	Mon Feb 18 14:12:07 2008 +0100
@@ -144,10 +144,8 @@
 	result = strcasestr (haystack, needle);
 	ASSERT (result == haystack + m);
       }
-    if (needle != NULL)
-      free (needle);
-    if (haystack != NULL)
-      free (haystack);
+    free (needle);
+    free (haystack);
   }
 
   return 0;
--- a/tests/test-striconv.c	Sun Mar 02 17:19:20 2008 +0100
+++ b/tests/test-striconv.c	Mon Feb 18 14:12:07 2008 +0100
@@ -102,8 +102,7 @@
 			       &result, &length);
     ASSERT (retval == 0);
     ASSERT (length == 0);
-    if (result != NULL)
-      free (result);
+    free (result);
   }
 
   /* ------------------------- Test str_cd_iconv() ------------------------- */
--- a/tests/test-striconveh.c	Sun Mar 02 17:19:20 2008 +0100
+++ b/tests/test-striconveh.c	Mon Feb 18 14:12:07 2008 +0100
@@ -330,8 +330,7 @@
 	      ASSERT (offsets[1] == MAGIC);
 	      free (offsets);
 	    }
-	  if (result != NULL)
-	    free (result);
+	  free (result);
 	}
     }
 
@@ -719,8 +718,7 @@
 	      ASSERT (offsets[1] == MAGIC);
 	      free (offsets);
 	    }
-	  if (result != NULL)
-	    free (result);
+	  free (result);
 	}
     }
 
--- a/tests/test-striconveha.c	Sun Mar 02 17:19:20 2008 +0100
+++ b/tests/test-striconveha.c	Mon Feb 18 14:12:07 2008 +0100
@@ -313,8 +313,7 @@
 	      ASSERT (offsets[1] == MAGIC);
 	      free (offsets);
 	    }
-	  if (result != NULL)
-	    free (result);
+	  free (result);
 	}
     }
 
--- a/tests/test-strstr.c	Sun Mar 02 17:19:20 2008 +0100
+++ b/tests/test-strstr.c	Mon Feb 18 14:12:07 2008 +0100
@@ -142,10 +142,8 @@
 	result = strstr (haystack, needle);
 	ASSERT (result == haystack + m);
       }
-    if (needle != NULL)
-      free (needle);
-    if (haystack != NULL)
-      free (haystack);
+    free (needle);
+    free (haystack);
   }
 
   /* Sublinear speed is only possible in memmem; strstr must examine