]> sourceware.org Git - lvm2.git/commitdiff
cleanup: free already checks for NULL
authorZdenek Kabelac <zkabelac@redhat.com>
Sat, 27 Feb 2021 13:14:25 +0000 (14:14 +0100)
committerZdenek Kabelac <zkabelac@redhat.com>
Tue, 2 Mar 2021 21:57:35 +0000 (22:57 +0100)
daemons/cmirrord/functions.c
daemons/lvmlockd/lvmlockd-dlm.c
daemons/lvmlockd/lvmlockd-sanlock.c
lib/cache/lvmcache.c
lib/device/device_id.c
lib/format_text/format-text.c
tools/pvchange.c

index f10a8d5bb6922ad016d4fd073654ec0cf37d9409..23a17015abcf31cd6633f0b5ab477b88aef10540 100644 (file)
@@ -658,8 +658,7 @@ static int clog_dtr(struct dm_ulog_request *rq)
        if (lc->disk_fd != -1 && close(lc->disk_fd))
                LOG_ERROR("Failed to close disk log: %s",
                          strerror(errno));
-       if (lc->disk_buffer)
-               free(lc->disk_buffer);
+       free(lc->disk_buffer);
        free(lc->clean_bits);
        free(lc->sync_bits);
        free(lc);
index 7915cc00828e70fd32f45411dedfbef85a1d234d..dc665e0a4ee2819927e32d87fb8aeb826fda19df 100644 (file)
@@ -327,8 +327,7 @@ int lm_rem_resource_dlm(struct lockspace *ls, struct resource *r)
                log_error("S %s R %s rem_resource_dlm unlock error %d", ls->name, r->name, rv);
        }
  out:
-       if (rdd->vb)
-               free(rdd->vb);
+       free(rdd->vb);
 
        memset(rdd, 0, sizeof(struct rd_dlm));
        r->lm_init = 0;
index 4bc6402cf85a374a49695c6bca5bc10a7e5f042b..36d57767ff270503d6a4d8b105741900a1d4a16a 100644 (file)
@@ -1503,8 +1503,7 @@ out:
 fail:
        if (lms && lms->sock)
                close(lms->sock);
-       if (lms)
-               free(lms);
+       free(lms);
        return ret;
 }
 
@@ -1634,8 +1633,7 @@ int lm_rem_resource_sanlock(struct lockspace *ls, struct resource *r)
 
        /* FIXME: assert r->mode == UN or unlock if it's not? */
 
-       if (rds->vb)
-               free(rds->vb);
+       free(rds->vb);
 
        memset(rds, 0, sizeof(struct rd_sanlock));
        r->lm_init = 0;
index 172c10f307b314a6610c3ade896ea8cbd663d64f..04f6fe0a549317dacad8021feb82946261c81a25 100644 (file)
@@ -1406,8 +1406,7 @@ static void _free_vginfo(struct lvmcache_vginfo *vginfo)
        free(vginfo->vgname);
        free(vginfo->system_id);
        free(vginfo->creation_host);
-       if (vginfo->lock_type)
-               free(vginfo->lock_type);
+       free(vginfo->lock_type);
        free(vginfo);
 }
 
index 698942bb162aabefbd228cdbde65cf4653c39b66..4b7214b600e8b38ac80574f64e6e20d9e76f9c5e 100644 (file)
@@ -149,12 +149,9 @@ static int _searched_devnames_exists(struct cmd_context *cmd)
 
 void free_du(struct dev_use *du)
 {
-       if (du->idname)
-               free(du->idname);
-       if (du->devname)
-               free(du->devname);
-       if (du->pvid)
-               free(du->pvid);
+       free(du->idname);
+       free(du->devname);
+       free(du->pvid);
        free(du);
 }
 
@@ -170,8 +167,7 @@ void free_dus(struct dm_list *dus)
 
 void free_did(struct dev_id *id)
 {
-       if (id->idname)
-               free(id->idname);
+       free(id->idname);
        free(id);
 }
 
@@ -1213,8 +1209,7 @@ id_done:
                du_devname->devname = NULL;
        }
 
-       if (check_idname)
-               free((void *)check_idname);
+       free((void *)check_idname);
 
        if (!update_du) {
                log_debug("Adding new entry to devices file for %s PVID %s %s %s.",
@@ -1227,12 +1222,9 @@ id_done:
                          dev_name(dev), update_matching_kind, update_matching_name);
        }
 
-       if (du->idname)
-               free(du->idname);
-       if (du->devname)
-               free(du->devname);
-       if (du->pvid)
-               free(du->pvid);
+       free(du->idname);
+       free(du->devname);
+       free(du->pvid);
 
        du->idtype = id->idtype;
        du->idname = strdup(id->idname);
@@ -1604,8 +1596,7 @@ void device_ids_validate(struct cmd_context *cmd, struct dm_list *scanned_devs,
                                         dev_name(dev), dev->pvid, du->pvid ?: "none");
                                if (!(tmpdup = strdup(dev->pvid)))
                                        continue;
-                               if (du->pvid)
-                                       free(du->pvid);
+                               free(du->pvid);
                                du->pvid = tmpdup;
                                update_file = 1;
                                *device_ids_invalid = 1;
@@ -1614,8 +1605,7 @@ void device_ids_validate(struct cmd_context *cmd, struct dm_list *scanned_devs,
                        if (du->pvid && (du->pvid[0] != '.')) {
                                log_warn("Device %s has no PVID (devices file %s)",
                                         dev_name(dev), du->pvid);
-                               if (du->pvid)
-                                       free(du->pvid);
+                               free(du->pvid);
                                du->pvid = NULL;
                                update_file = 1;
                                *device_ids_invalid = 1;
@@ -1627,8 +1617,7 @@ void device_ids_validate(struct cmd_context *cmd, struct dm_list *scanned_devs,
                                 dev_name(du->dev), du->devname ?: "none");
                        if (!(tmpdup = strdup(dev_name(du->dev))))
                                continue;
-                       if (du->devname)
-                               free(du->devname);
+                       free(du->devname);
                        du->devname = tmpdup;
                        update_file = 1;
                        *device_ids_invalid = 1;
@@ -1686,8 +1675,7 @@ void device_ids_validate(struct cmd_context *cmd, struct dm_list *scanned_devs,
                                         devname, du->devname ?: "none");
                                if (!(tmpdup = strdup(devname)))
                                        continue;
-                               if (du->devname)
-                                       free(du->devname);
+                               free(du->devname);
                                du->devname = tmpdup;
                                update_file = 1;
                                *device_ids_invalid = 1;
@@ -2029,24 +2017,18 @@ void device_ids_find_renamed_devs(struct cmd_context *cmd, struct dm_list *dev_l
                dup_devname3 = strdup(devname);
                id = zalloc(sizeof(struct dev_id));
                if (!dup_devname1 || !dup_devname2 || !dup_devname3 || !id) {
-                       if (dup_devname1)
-                               free(dup_devname1);
-                       if (dup_devname2)
-                               free(dup_devname2);
-                       if (dup_devname3)
-                               free(dup_devname3);
-                       if (id)
-                               free(id);
+                       free(dup_devname1);
+                       free(dup_devname2);
+                       free(dup_devname3);
+                       free(id);
                        stack;
                        continue;
                }
 
                log_warn("Devices file PVID %s updating IDNAME to %s.", dev->pvid, devname);
 
-               if (du->idname)
-                       free(du->idname);
-               if (du->devname)
-                       free(du->devname);
+               free(du->idname);
+               free(du->devname);
                free_dids(&dev->ids);
 
                du->idname = dup_devname1;
index e1142c07ef870407408666a6d57153acfd37222b..e8533d5dcf5db6158210a8c192ccd434c415dd56 100644 (file)
@@ -63,8 +63,7 @@ void free_text_fidtc(struct volume_group *vg)
 
        fidtc->preserve = 0;
 
-       if (fidtc->write_buf)
-               free(fidtc->write_buf);
+       free(fidtc->write_buf);
        fidtc->write_buf = NULL;
        fidtc->write_buf_size = 0;
        fidtc->new_metadata_size = 0;
@@ -2018,9 +2017,7 @@ static void _text_destroy(struct format_type *fmt)
        if (fmt->orphan_vg)
                free_orphan_vg(fmt->orphan_vg);
 
-       if (fmt->private)
-               free(fmt->private);
-
+       free(fmt->private);
        free(fmt);
 }
 
index 5e457a60be7933fb6bf207462be34f3e1bd461cb..b0bc83ed5a37dc41e80c9c17684a9c55b0fd9f10 100644 (file)
@@ -189,8 +189,7 @@ static int _pvchange_single(struct cmd_context *cmd, struct volume_group *vg,
        }
 
        if (du) {
-               if (du->pvid)
-                       free(du->pvid);
+               free(du->pvid);
                if (!(du->pvid = strndup((char *)&pv->id, ID_LEN)))
                        log_error("Failed to set pvid for devices file.");
                if (!device_ids_write(cmd))
This page took 0.051149 seconds and 5 git commands to generate.