[PATCH] remove more useless "if" tests before free
Jim Meyering
meyering at redhat.com
Sun May 4 07:55:00 UTC 2008
* libparted/arch/gnu.c (gnu_sync):
* libparted/cs/natmath.c (ped_alignment_destroy):
* libparted/exception.c (ped_exception_catch):
* libparted/labels/dos.c (msdos_partition_destroy):
* parted/parted.c (do_mkpart, do_mkpartfs):
---
libparted/arch/gnu.c | 3 +-
libparted/cs/natmath.c | 3 +-
libparted/exception.c | 4 +-
libparted/labels/dos.c | 3 +-
libparted/labels/gpt.c | 2 +-
parted/parted.c | 51 ++++++++++++++++--------------------------------
6 files changed, 23 insertions(+), 43 deletions(-)
diff --git a/libparted/arch/gnu.c b/libparted/arch/gnu.c
index 0b5c2ee..6c619e4 100644
--- a/libparted/arch/gnu.c
+++ b/libparted/arch/gnu.c
@@ -775,8 +775,7 @@ gnu_sync (PedDevice* dev)
switch (ex_status) {
case PED_EXCEPTION_IGNORE:
- if (last_failure)
- free (last_failure);
+ free (last_failure);
last_failure = strdup (dev->path);
return 1;
diff --git a/libparted/cs/natmath.c b/libparted/cs/natmath.c
index 281b4d3..7511fbd 100644
--- a/libparted/cs/natmath.c
+++ b/libparted/cs/natmath.c
@@ -171,8 +171,7 @@ error:
void
ped_alignment_destroy (PedAlignment* align)
{
- if (align)
- free (align);
+ free (align);
}
/**
diff --git a/libparted/exception.c b/libparted/exception.c
index c9eba25..46e08b2 100644
--- a/libparted/exception.c
+++ b/libparted/exception.c
@@ -188,8 +188,8 @@ ped_exception_catch ()
{
if (ped_exception) {
ped_exception = 0;
- if (ex->message) free (ex->message);
- if (ex) free (ex);
+ free (ex->message);
+ free (ex);
ex = NULL;
}
}
diff --git a/libparted/labels/dos.c b/libparted/labels/dos.c
index ad9b298..cb7e45e 100644
--- a/libparted/labels/dos.c
+++ b/libparted/labels/dos.c
@@ -1256,8 +1256,7 @@ msdos_partition_destroy (PedPartition* part)
if (ped_partition_is_active (part)) {
DosPartitionData* dos_data;
dos_data = (DosPartitionData*) part->disk_specific;
- if (dos_data->orig)
- free (dos_data->orig);
+ free (dos_data->orig);
free (part->disk_specific);
}
free (part);
diff --git a/libparted/labels/gpt.c b/libparted/labels/gpt.c
index ec008a3..8bb9554 100644
--- a/libparted/labels/gpt.c
+++ b/libparted/labels/gpt.c
@@ -620,7 +620,7 @@ _read_header (const PedDevice* dev, GuidPartitionTableHeader_t** gpt,
PED_ASSERT (dev != NULL, return 0);
if (!ped_device_read (dev, pth_raw, where, GPT_HEADER_SECTORS)) {
- free (pth_raw);
+ free (pth_raw);
return 0;
}
diff --git a/parted/parted.c b/parted/parted.c
index 6b8e0ff..4e16f92 100644
--- a/parted/parted.c
+++ b/parted/parted.c
@@ -733,8 +733,7 @@ do_mkpart (PedDevice** dev)
&fs_type))
goto error_destroy_disk;
}
- if (peek_word)
- free (peek_word);
+ free (peek_word);
if (!command_line_get_sector (_("Start?"), *dev, &start, &range_start))
goto error_destroy_disk;
@@ -822,14 +821,10 @@ do_mkpart (PedDevice** dev)
if (range_end != NULL)
ped_geometry_destroy (range_end);
- if (start_usr != NULL)
- free (start_usr);
- if (end_usr != NULL)
- free (end_usr);
- if (start_sol != NULL)
- free (start_sol);
- if (end_sol != NULL)
- free (end_sol);
+ free (start_usr);
+ free (end_usr);
+ free (start_sol);
+ free (end_sol);
if ((*dev)->type != PED_DEVICE_FILE)
disk_is_modified = 1;
@@ -851,14 +846,10 @@ error:
if (range_end != NULL)
ped_geometry_destroy (range_end);
- if (start_usr != NULL)
- free (start_usr);
- if (end_usr != NULL)
- free (end_usr);
- if (start_sol != NULL)
- free (start_sol);
- if (end_sol != NULL)
- free (end_sol);
+ free (start_usr);
+ free (end_usr);
+ free (start_sol);
+ free (end_sol);
return 0;
}
@@ -997,14 +988,10 @@ do_mkpartfs (PedDevice** dev)
if (range_end != NULL)
ped_geometry_destroy (range_end);
- if (start_usr != NULL)
- free (start_usr);
- if (end_usr != NULL)
- free (end_usr);
- if (start_sol != NULL)
- free (start_sol);
- if (end_sol != NULL)
- free (end_sol);
+ free (start_usr);
+ free (end_usr);
+ free (start_sol);
+ free (end_sol);
if ((*dev)->type != PED_DEVICE_FILE)
disk_is_modified = 1;
@@ -1026,14 +1013,10 @@ error:
if (range_end != NULL)
ped_geometry_destroy (range_end);
- if (start_usr != NULL)
- free (start_usr);
- if (end_usr != NULL)
- free (end_usr);
- if (start_sol != NULL)
- free (start_sol);
- if (end_sol != NULL)
- free (end_sol);
+ free (start_usr);
+ free (end_usr);
+ free (start_sol);
+ free (end_sol);
return 0;
}
--
1.5.6.rc0.30.g51263
More information about the parted-devel
mailing list