svn commit: trunk/uClibc/libc: inet/rpc misc/glob misc/regex misc/searc etc...

vda at uclibc.org vda at uclibc.org
Tue May 20 20:39:41 UTC 2008


Author: vda
Date: 2008-05-20 13:39:38 -0700 (Tue, 20 May 2008)
New Revision: 22028

Log:
replace "if (p) free(p)" by just "free(p)" - free(NULL) is safe.



Modified:
   trunk/uClibc/libc/inet/rpc/auth_unix.c
   trunk/uClibc/libc/inet/rpc/getrpcent.c
   trunk/uClibc/libc/inet/rpc/rcmd.c
   trunk/uClibc/libc/misc/glob/glob.c
   trunk/uClibc/libc/misc/regex/regex_old.c
   trunk/uClibc/libc/misc/search/_hsearch_r.c
   trunk/uClibc/libc/misc/wordexp/wordexp.c
   trunk/uClibc/libc/stdio/open_memstream.c
   trunk/uClibc/libc/stdlib/_atexit.c
   trunk/uClibc/libc/sysdeps/linux/common/getgroups.c
   trunk/uClibc/libc/sysdeps/linux/common/setgroups.c
   trunk/uClibc/libc/unistd/usershell.c


Changeset:
Modified: trunk/uClibc/libc/inet/rpc/auth_unix.c
===================================================================
--- trunk/uClibc/libc/inet/rpc/auth_unix.c	2008-05-20 20:32:27 UTC (rev 22027)
+++ trunk/uClibc/libc/inet/rpc/auth_unix.c	2008-05-20 20:39:38 UTC (rev 22028)
@@ -212,8 +212,7 @@
      list of groups to NGRPS members since the code in
      authuxprot.c transforms a fixed array.  Grrr.  */
   ret_auth = authunix_create (machname, uid, gid, MIN (NGRPS, len), gids);
-  if (gids)
-    free (gids);
+  free (gids);
   return ret_auth;
 }
 libc_hidden_def(authunix_create_default)

Modified: trunk/uClibc/libc/inet/rpc/getrpcent.c
===================================================================
--- trunk/uClibc/libc/inet/rpc/getrpcent.c	2008-05-20 20:32:27 UTC (rev 22027)
+++ trunk/uClibc/libc/inet/rpc/getrpcent.c	2008-05-20 20:39:38 UTC (rev 22028)
@@ -93,10 +93,8 @@
 		return;
 	if (d->stayopen)
 		return;
-	if (d->current) {
-		free(d->current);
-		d->current = NULL;
-	}
+	free(d->current);
+	d->current = NULL;
 	if (d->rpcf) {
 		fclose(d->rpcf);
 		d->rpcf = NULL;
@@ -115,8 +113,7 @@
 		d->rpcf = fopen(RPCDB, "r");
 	else
 		rewind(d->rpcf);
-	if (d->current)
-		free(d->current);
+	free(d->current);
 	d->current = NULL;
 	d->stayopen |= f;
 }

Modified: trunk/uClibc/libc/inet/rpc/rcmd.c
===================================================================
--- trunk/uClibc/libc/inet/rpc/rcmd.c	2008-05-20 20:32:27 UTC (rev 22027)
+++ trunk/uClibc/libc/inet/rpc/rcmd.c	2008-05-20 20:39:38 UTC (rev 22028)
@@ -197,9 +197,7 @@
 #ifdef __ARCH_USE_MMU__
 		tmphstbuf = alloca (hstbuflen);
 #else
-		if (tmphstbuf) {
-		    free(tmphstbuf);
-		}
+		free(tmphstbuf);
 		tmphstbuf = malloc (hstbuflen);
 #endif
 	    }
@@ -411,9 +409,7 @@
 #ifdef __ARCH_USE_MMU__
 		buffer = alloca (buflen);
 #else
-		if (buffer) {
-		    free(buffer);
-		}
+		free(buffer);
 		buffer = malloc (buflen);
 #endif
 	    }
@@ -780,8 +776,7 @@
 	}
     }
 
-    if (buf != NULL)
-      free (buf);
+    free (buf);
 
     return retval;
 }

Modified: trunk/uClibc/libc/misc/glob/glob.c
===================================================================
--- trunk/uClibc/libc/misc/glob/glob.c	2008-05-20 20:32:27 UTC (rev 22027)
+++ trunk/uClibc/libc/misc/glob/glob.c	2008-05-20 20:39:38 UTC (rev 22028)
@@ -482,8 +482,7 @@
   }
   while (names != NULL)
     {
-      if (names->name != NULL)
-	free (names->name);
+      free (names->name);
       names = names->next;
     }
   return GLOB_NOSPACE;

Modified: trunk/uClibc/libc/misc/regex/regex_old.c
===================================================================
--- trunk/uClibc/libc/misc/regex/regex_old.c	2008-05-20 20:32:27 UTC (rev 22027)
+++ trunk/uClibc/libc/misc/regex/regex_old.c	2008-05-20 20:39:38 UTC (rev 22028)
@@ -5132,7 +5132,7 @@
 #ifdef MATCH_MAY_ALLOCATE
 # define FREE_VAR(var) if (var) REGEX_FREE (var); var = NULL
 #else
-# define FREE_VAR(var) if (var) free (var); var = NULL
+# define FREE_VAR(var) free (var); var = NULL
 #endif
 
 #ifdef WCHAR
@@ -8313,20 +8313,17 @@
 regfree (preg)
     regex_t *preg;
 {
-  if (preg->buffer != NULL)
-    free (preg->buffer);
+  free (preg->buffer);
   preg->buffer = NULL;
 
   preg->allocated = 0;
   preg->used = 0;
 
-  if (preg->fastmap != NULL)
-    free (preg->fastmap);
+  free (preg->fastmap);
   preg->fastmap = NULL;
   preg->fastmap_accurate = 0;
 
-  if (preg->translate != NULL)
-    free (preg->translate);
+  free (preg->translate);
   preg->translate = NULL;
 }
 #if defined _LIBC || defined __UCLIBC__

Modified: trunk/uClibc/libc/misc/search/_hsearch_r.c
===================================================================
--- trunk/uClibc/libc/misc/search/_hsearch_r.c	2008-05-20 20:32:27 UTC (rev 22027)
+++ trunk/uClibc/libc/misc/search/_hsearch_r.c	2008-05-20 20:39:38 UTC (rev 22028)
@@ -110,9 +110,8 @@
       return;
     }
 
-  if (htab->table != NULL)
-    /* free used memory */
-    free (htab->table);
+  /* free used memory */
+  free (htab->table);
 
   /* the sign for an existing table is an value != NULL in htable */
   htab->table = NULL;

Modified: trunk/uClibc/libc/misc/wordexp/wordexp.c
===================================================================
--- trunk/uClibc/libc/misc/wordexp/wordexp.c	2008-05-20 20:32:27 UTC (rev 22027)
+++ trunk/uClibc/libc/misc/wordexp/wordexp.c	2008-05-20 20:39:38 UTC (rev 22028)
@@ -1076,8 +1076,7 @@
 	}
 
 	/* Premature end */
-	if (comm)
-		free(comm);
+	free(comm);
 
 	return WRDE_SYNTAX;
 }
@@ -1370,8 +1369,7 @@
 							   &buffer[20]);
 			*word = w_addstr(*word, word_length, max_length, value);
 			free(env);
-			if (pattern)
-				free(pattern);
+			free(pattern);
 			return *word ? 0 : WRDE_NOSPACE;
 		}
 		/* Is it `$*' or `$@' (unquoted) ? */
@@ -1530,8 +1528,7 @@
 						if (free_value)
 							free(value);
 
-						if (expanded)
-							free(expanded);
+						free(expanded);
 
 						goto do_error;
 					}
@@ -1550,8 +1547,7 @@
 						if (free_value)
 							free(value);
 
-						if (expanded)
-							free(expanded);
+						free(expanded);
 
 						goto do_error;
 					}
@@ -1573,8 +1569,7 @@
 					goto no_space;
 			}
 
-			if (pattern)
-				free(pattern);
+			free(pattern);
 
 			pattern = expanded;
 		}
@@ -1723,7 +1718,7 @@
 				/* Substitute parameter */
 				break;
 
-			if (free_value && value)
+			if (free_value)
 				free(value);
 
 			if (!colon_seen && value)
@@ -1740,7 +1735,7 @@
 
 		case ACT_NONNULL_SUBST:
 			if (value && (*value || !colon_seen)) {
-				if (free_value && value)
+				if (free_value)
 					free(value);
 
 				value = pattern ? strdup(pattern) : pattern;
@@ -1769,7 +1764,7 @@
 				goto success;
 			}
 
-			if (free_value && value)
+			if (free_value)
 				free(value);
 
 			value = pattern ? strdup(pattern) : pattern;
@@ -1895,11 +1890,9 @@
 	error = WRDE_SYNTAX;
 
   do_error:
-	if (env)
-		free(env);
+	free(env);
 
-	if (pattern)
-		free(pattern);
+	free(pattern);
 
 	return error;
 }
@@ -2269,8 +2262,7 @@
 	 *  set we members back to what they were.
 	 */
 
-	if (word != NULL)
-		free(word);
+	free(word);
 
 	if (error == WRDE_NOSPACE)
 		return WRDE_NOSPACE;

Modified: trunk/uClibc/libc/stdio/open_memstream.c
===================================================================
--- trunk/uClibc/libc/stdio/open_memstream.c	2008-05-20 20:32:27 UTC (rev 22027)
+++ trunk/uClibc/libc/stdio/open_memstream.c	2008-05-20 20:39:38 UTC (rev 22028)
@@ -160,9 +160,7 @@
 		}
 	}
 
-	if (cookie->buf != NULL) {
-		free(cookie->buf);
-	}
+	free(cookie->buf);
  EXIT_cookie:
 	free(cookie);
 

Modified: trunk/uClibc/libc/stdlib/_atexit.c
===================================================================
--- trunk/uClibc/libc/stdlib/_atexit.c	2008-05-20 20:32:27 UTC (rev 22027)
+++ trunk/uClibc/libc/stdlib/_atexit.c	2008-05-20 20:39:38 UTC (rev 22028)
@@ -298,8 +298,7 @@
 	}
 #ifdef __UCLIBC_DYNAMIC_ATEXIT__
 	/* Free up memory used by the __exit_function_table structure */
-	if (__exit_function_table)
-	    free(__exit_function_table);
+	free(__exit_function_table);
 #endif
 }
 #endif

Modified: trunk/uClibc/libc/sysdeps/linux/common/getgroups.c
===================================================================
--- trunk/uClibc/libc/sysdeps/linux/common/getgroups.c	2008-05-20 20:32:27 UTC (rev 22027)
+++ trunk/uClibc/libc/sysdeps/linux/common/getgroups.c	2008-05-20 20:39:38 UTC (rev 22028)
@@ -53,8 +53,7 @@
 			}
 		}
 
-		if (kernel_groups)
-			free(kernel_groups);
+		free(kernel_groups);
 		return ngids;
 	}
 }

Modified: trunk/uClibc/libc/sysdeps/linux/common/setgroups.c
===================================================================
--- trunk/uClibc/libc/sysdeps/linux/common/setgroups.c	2008-05-20 20:32:27 UTC (rev 22027)
+++ trunk/uClibc/libc/sysdeps/linux/common/setgroups.c	2008-05-20 20:39:38 UTC (rev 22028)
@@ -56,8 +56,7 @@
 		}
 
 		i = __syscall_setgroups(size, kernel_groups);
-		if (kernel_groups)
-			free(kernel_groups);
+		free(kernel_groups);
 		return i;
 	}
 }

Modified: trunk/uClibc/libc/unistd/usershell.c
===================================================================
--- trunk/uClibc/libc/unistd/usershell.c	2008-05-20 20:32:27 UTC (rev 22027)
+++ trunk/uClibc/libc/unistd/usershell.c	2008-05-20 20:39:38 UTC (rev 22028)
@@ -80,13 +80,9 @@
 
 static void __free_initshell_memory(void)
 {
-    if (shells != NULL) {
-	free(shells);
-    }
+    free(shells);
     shells = NULL;
-    if (strings != NULL) {
-	free(strings);
-    }
+    free(strings);
     strings = NULL;
 }
 
@@ -98,7 +94,6 @@
 
 void setusershell(void)
 {
-
     curshell = initshells();
 }
 




More information about the uClibc-cvs mailing list