[PATCH v2 3/3] nilfs-utils: get rid of null checks before calling free()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Remove unnecessary null checks before calling free() function.

Signed-off-by: Ryusuke Konishi <konishi.ryusuke@xxxxxxxxxxxxx>
---
 lib/cleaner_ctl.c |  6 ++----
 lib/gc.c          |  3 +--
 lib/nilfs.c       | 19 +++++++------------
 lib/realpath.c    |  9 +++------
 4 files changed, 13 insertions(+), 24 deletions(-)

diff --git a/lib/cleaner_ctl.c b/lib/cleaner_ctl.c
index fa41ac1..9c458a4 100644
--- a/lib/cleaner_ctl.c
+++ b/lib/cleaner_ctl.c
@@ -226,8 +226,7 @@ static int nilfs_cleaner_find_fs(struct nilfs_cleaner *cleaner,
 					       sizeof(canonical))) {
 					mdev = canonical;
 				}
-				if (last_match_dev)
-					free(last_match_dev);
+				free(last_match_dev);
 				last_match_dev = strdup(mdev);
 				if (!last_match_dev)
 					goto error;
@@ -238,8 +237,7 @@ static int nilfs_cleaner_find_fs(struct nilfs_cleaner *cleaner,
 					       sizeof(canonical))) {
 					mdir = canonical;
 				}
-				if (last_match_dir)
-					free(last_match_dir);
+				free(last_match_dir);
 				last_match_dir = strdup(mdir);
 				if (!last_match_dir)
 					goto error;
diff --git a/lib/gc.c b/lib/gc.c
index 54d0b66..48c295a 100644
--- a/lib/gc.c
+++ b/lib/gc.c
@@ -508,8 +508,7 @@ static int nilfs_toss_vdescs(struct nilfs *nilfs,
 	}
 	ret = 0;
  out:
-	if (ss != NULL)
-		free(ss);
+	free(ss);
 	return ret;
 }
 
diff --git a/lib/nilfs.c b/lib/nilfs.c
index 52ddee9..30db654 100644
--- a/lib/nilfs.c
+++ b/lib/nilfs.c
@@ -435,13 +435,10 @@ out_fd:
 		close(nilfs->n_devfd);
 	if (nilfs->n_iocfd >= 0)
 		close(nilfs->n_iocfd);
-	if (nilfs->n_dev != NULL)
-		free(nilfs->n_dev);
-	if (nilfs->n_ioc != NULL)
-		free(nilfs->n_ioc);
-	if (nilfs->n_sb != NULL)
-		free(nilfs->n_sb);
 
+	free(nilfs->n_dev);
+	free(nilfs->n_ioc);
+	free(nilfs->n_sb);
 	free(nilfs);
 	return NULL;
 }
@@ -458,12 +455,10 @@ void nilfs_close(struct nilfs *nilfs)
 		close(nilfs->n_devfd);
 	if (nilfs->n_iocfd >= 0)
 		close(nilfs->n_iocfd);
-	if (nilfs->n_dev != NULL)
-		free(nilfs->n_dev);
-	if (nilfs->n_ioc != NULL)
-		free(nilfs->n_ioc);
-	if (nilfs->n_sb != NULL)
-		free(nilfs->n_sb);
+
+	free(nilfs->n_dev);
+	free(nilfs->n_ioc);
+	free(nilfs->n_sb);
 	free(nilfs);
 }
 
diff --git a/lib/realpath.c b/lib/realpath.c
index 3f01b87..691360b 100644
--- a/lib/realpath.c
+++ b/lib/realpath.c
@@ -133,8 +133,7 @@ myrealpath(const char *path, char *resolved_path, int maxreslth) {
 
 			/* Insert symlink contents into path. */
 			m = strlen(path);
-			if (buf)
-				free(buf);
+			free(buf);
 			buf = malloc(m + n + 1);
 			if (!buf) {
 				errno = ENOMEM;
@@ -153,12 +152,10 @@ myrealpath(const char *path, char *resolved_path, int maxreslth) {
 	/* Make sure it's null terminated. */
 	*npath = '\0';
 
-	if (buf)
-		free(buf);
+	free(buf);
 	return resolved_path;
 
  err:
-	if (buf)
-		free(buf);
+	free(buf);
 	return NULL;
 }
-- 
1.8.3.1

--
To unsubscribe from this list: send the line "unsubscribe linux-nilfs" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Linux Filesystem Development]     [Linux BTRFS]     [Linux CIFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux SCSI]

  Powered by Linux