1
0
mirror of git://sourceware.org/git/lvm2.git synced 2024-12-21 13:34:40 +03:00

cleanup: free already checks for NULL

This commit is contained in:
Zdenek Kabelac 2021-02-27 14:14:25 +01:00
parent 0b7a4503e5
commit eb3dcc72eb
7 changed files with 26 additions and 53 deletions

View 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);

View 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;

View 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;

View 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);
}

View 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;

View 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);
}

View 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))