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,7 +658,6 @@ static int clog_dtr(struct dm_ulog_request *rq)
if (lc->disk_fd != -1 && close(lc->disk_fd)) if (lc->disk_fd != -1 && close(lc->disk_fd))
LOG_ERROR("Failed to close disk log: %s", LOG_ERROR("Failed to close disk log: %s",
strerror(errno)); strerror(errno));
if (lc->disk_buffer)
free(lc->disk_buffer); free(lc->disk_buffer);
free(lc->clean_bits); free(lc->clean_bits);
free(lc->sync_bits); free(lc->sync_bits);

View File

@ -327,7 +327,6 @@ 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); log_error("S %s R %s rem_resource_dlm unlock error %d", ls->name, r->name, rv);
} }
out: out:
if (rdd->vb)
free(rdd->vb); free(rdd->vb);
memset(rdd, 0, sizeof(struct rd_dlm)); memset(rdd, 0, sizeof(struct rd_dlm));

View File

@ -1503,7 +1503,6 @@ out:
fail: fail:
if (lms && lms->sock) if (lms && lms->sock)
close(lms->sock); close(lms->sock);
if (lms)
free(lms); free(lms);
return ret; return ret;
} }
@ -1634,7 +1633,6 @@ int lm_rem_resource_sanlock(struct lockspace *ls, struct resource *r)
/* FIXME: assert r->mode == UN or unlock if it's not? */ /* 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)); memset(rds, 0, sizeof(struct rd_sanlock));

View File

@ -1406,7 +1406,6 @@ static void _free_vginfo(struct lvmcache_vginfo *vginfo)
free(vginfo->vgname); free(vginfo->vgname);
free(vginfo->system_id); free(vginfo->system_id);
free(vginfo->creation_host); free(vginfo->creation_host);
if (vginfo->lock_type)
free(vginfo->lock_type); free(vginfo->lock_type);
free(vginfo); free(vginfo);
} }

View File

@ -149,11 +149,8 @@ static int _searched_devnames_exists(struct cmd_context *cmd)
void free_du(struct dev_use *du) void free_du(struct dev_use *du)
{ {
if (du->idname)
free(du->idname); free(du->idname);
if (du->devname)
free(du->devname); free(du->devname);
if (du->pvid)
free(du->pvid); free(du->pvid);
free(du); free(du);
} }
@ -170,7 +167,6 @@ void free_dus(struct dm_list *dus)
void free_did(struct dev_id *id) void free_did(struct dev_id *id)
{ {
if (id->idname)
free(id->idname); free(id->idname);
free(id); free(id);
} }
@ -1213,7 +1209,6 @@ id_done:
du_devname->devname = NULL; du_devname->devname = NULL;
} }
if (check_idname)
free((void *)check_idname); free((void *)check_idname);
if (!update_du) { if (!update_du) {
@ -1227,11 +1222,8 @@ id_done:
dev_name(dev), update_matching_kind, update_matching_name); dev_name(dev), update_matching_kind, update_matching_name);
} }
if (du->idname)
free(du->idname); free(du->idname);
if (du->devname)
free(du->devname); free(du->devname);
if (du->pvid)
free(du->pvid); free(du->pvid);
du->idtype = id->idtype; du->idtype = id->idtype;
@ -1604,7 +1596,6 @@ void device_ids_validate(struct cmd_context *cmd, struct dm_list *scanned_devs,
dev_name(dev), dev->pvid, du->pvid ?: "none"); dev_name(dev), dev->pvid, du->pvid ?: "none");
if (!(tmpdup = strdup(dev->pvid))) if (!(tmpdup = strdup(dev->pvid)))
continue; continue;
if (du->pvid)
free(du->pvid); free(du->pvid);
du->pvid = tmpdup; du->pvid = tmpdup;
update_file = 1; update_file = 1;
@ -1614,7 +1605,6 @@ void device_ids_validate(struct cmd_context *cmd, struct dm_list *scanned_devs,
if (du->pvid && (du->pvid[0] != '.')) { if (du->pvid && (du->pvid[0] != '.')) {
log_warn("Device %s has no PVID (devices file %s)", log_warn("Device %s has no PVID (devices file %s)",
dev_name(dev), du->pvid); dev_name(dev), du->pvid);
if (du->pvid)
free(du->pvid); free(du->pvid);
du->pvid = NULL; du->pvid = NULL;
update_file = 1; update_file = 1;
@ -1627,7 +1617,6 @@ void device_ids_validate(struct cmd_context *cmd, struct dm_list *scanned_devs,
dev_name(du->dev), du->devname ?: "none"); dev_name(du->dev), du->devname ?: "none");
if (!(tmpdup = strdup(dev_name(du->dev)))) if (!(tmpdup = strdup(dev_name(du->dev))))
continue; continue;
if (du->devname)
free(du->devname); free(du->devname);
du->devname = tmpdup; du->devname = tmpdup;
update_file = 1; update_file = 1;
@ -1686,7 +1675,6 @@ void device_ids_validate(struct cmd_context *cmd, struct dm_list *scanned_devs,
devname, du->devname ?: "none"); devname, du->devname ?: "none");
if (!(tmpdup = strdup(devname))) if (!(tmpdup = strdup(devname)))
continue; continue;
if (du->devname)
free(du->devname); free(du->devname);
du->devname = tmpdup; du->devname = tmpdup;
update_file = 1; update_file = 1;
@ -2029,13 +2017,9 @@ void device_ids_find_renamed_devs(struct cmd_context *cmd, struct dm_list *dev_l
dup_devname3 = strdup(devname); dup_devname3 = strdup(devname);
id = zalloc(sizeof(struct dev_id)); id = zalloc(sizeof(struct dev_id));
if (!dup_devname1 || !dup_devname2 || !dup_devname3 || !id) { if (!dup_devname1 || !dup_devname2 || !dup_devname3 || !id) {
if (dup_devname1)
free(dup_devname1); free(dup_devname1);
if (dup_devname2)
free(dup_devname2); free(dup_devname2);
if (dup_devname3)
free(dup_devname3); free(dup_devname3);
if (id)
free(id); free(id);
stack; stack;
continue; continue;
@ -2043,9 +2027,7 @@ void device_ids_find_renamed_devs(struct cmd_context *cmd, struct dm_list *dev_l
log_warn("Devices file PVID %s updating IDNAME to %s.", dev->pvid, devname); log_warn("Devices file PVID %s updating IDNAME to %s.", dev->pvid, devname);
if (du->idname)
free(du->idname); free(du->idname);
if (du->devname)
free(du->devname); free(du->devname);
free_dids(&dev->ids); free_dids(&dev->ids);

View File

@ -63,7 +63,6 @@ void free_text_fidtc(struct volume_group *vg)
fidtc->preserve = 0; fidtc->preserve = 0;
if (fidtc->write_buf)
free(fidtc->write_buf); free(fidtc->write_buf);
fidtc->write_buf = NULL; fidtc->write_buf = NULL;
fidtc->write_buf_size = 0; fidtc->write_buf_size = 0;
@ -2018,9 +2017,7 @@ static void _text_destroy(struct format_type *fmt)
if (fmt->orphan_vg) if (fmt->orphan_vg)
free_orphan_vg(fmt->orphan_vg); free_orphan_vg(fmt->orphan_vg);
if (fmt->private)
free(fmt->private); free(fmt->private);
free(fmt); free(fmt);
} }

View File

@ -189,7 +189,6 @@ static int _pvchange_single(struct cmd_context *cmd, struct volume_group *vg,
} }
if (du) { if (du) {
if (du->pvid)
free(du->pvid); free(du->pvid);
if (!(du->pvid = strndup((char *)&pv->id, ID_LEN))) if (!(du->pvid = strndup((char *)&pv->id, ID_LEN)))
log_error("Failed to set pvid for devices file."); log_error("Failed to set pvid for devices file.");