[pve-devel] [PATCH cluster 2/3] pmxcfs: cleanup: remove unnecessary checks before free

Wolfgang Bumiller w.bumiller at proxmox.com
Wed Nov 9 09:15:55 CET 2016


---
both free(3) and g_free() document that passing NULL results in a no-op

 data/src/confdb.c |  4 ++--
 data/src/memdb.c  | 26 +++++++++++++-------------
 2 files changed, 15 insertions(+), 15 deletions(-)

diff --git a/data/src/confdb.c b/data/src/confdb.c
index 813283d..7c56119 100644
--- a/data/src/confdb.c
+++ b/data/src/confdb.c
@@ -82,7 +82,7 @@ cmap_read_clusternodes(
 				cfs_clinfo_add_node(clinfo, clnode);
 			}
 			last_id = id;
-			if (name) free(name);
+			free(name);
 			name = NULL;
 			nodeid = 0;
 			votes = 0;
@@ -116,7 +116,7 @@ cmap_read_clusternodes(
 		cfs_clnode_t *clnode = cfs_clnode_new(name, nodeid, votes);
 		cfs_clinfo_add_node(clinfo, clnode);
 	}
-	if (name) free(name);
+	free(name);
 
         result = cmap_iter_finalize(handle, iter);
  	if (result != CS_OK) {
diff --git a/data/src/memdb.c b/data/src/memdb.c
index 1c95e95..f35257b 100644
--- a/data/src/memdb.c
+++ b/data/src/memdb.c
@@ -306,8 +306,8 @@ path_contain_vm_config(
 	if (name_is_vm_config(base, vmid_ret))
 		nodename = dir_contain_vm_config(dirname, vmtype_ret);
 	
-	if (dirname) g_free (dirname);
-	if (base) g_free (base);
+	g_free (dirname);
+	g_free (base);
 
 	return nodename;
 }
@@ -653,8 +653,8 @@ int memdb_mkdir(
  ret:
 	g_mutex_unlock (&memdb->mutex);
 
-	if (dirname) g_free (dirname);
-	if (base) g_free (base);
+	g_free (dirname);
+	g_free (base);
 
 	return ret;
 }
@@ -851,9 +851,9 @@ memdb_pwrite(
  ret:
 	g_mutex_unlock (&memdb->mutex);
 
-	if (nodename) g_free (nodename);
-	if (dirname) g_free (dirname);
-	if (base) g_free (base);
+	g_free (nodename);
+	g_free (dirname);
+	g_free (base);
 
 	return ret;
 }
@@ -960,8 +960,8 @@ memdb_mtime(
  ret:
 	g_mutex_unlock (&memdb->mutex);
 
-	if (dirname) g_free (dirname);
-	if (base) g_free (base);
+	g_free (dirname);
+	g_free (base);
 
 	return ret;
 }
@@ -1241,10 +1241,10 @@ memdb_rename(
  ret:
 	g_mutex_unlock (&memdb->mutex);
 
-	if (from_node) g_free(from_node);
-	if (nodename) g_free (nodename);
-	if (dirname) g_free (dirname);
-	if (base) g_free (base);
+	g_free(from_node);
+	g_free (nodename);
+	g_free (dirname);
+	g_free (base);
 
 	return ret;
 }
-- 
2.1.4





More information about the pve-devel mailing list