From 406ec4162f86d872e041d7aa524d1f7dfd0d1cc0 Mon Sep 17 00:00:00 2001 From: Zdenek Kabelac Date: Mon, 24 Mar 2014 09:20:18 +0100 Subject: [PATCH] cleanup: use dm_free without extra test It's ok to free(NULL). --- daemons/dmeventd/libdevmapper-event.c | 8 ++++---- lib/cache/lvmetad.c | 3 +-- lib/format_text/format-text.c | 13 +++++-------- tools/pvscan.c | 6 ++---- 4 files changed, 12 insertions(+), 18 deletions(-) diff --git a/daemons/dmeventd/libdevmapper-event.c b/daemons/dmeventd/libdevmapper-event.c index 80d44207f..b6e2f0d26 100644 --- a/daemons/dmeventd/libdevmapper-event.c +++ b/daemons/dmeventd/libdevmapper-event.c @@ -700,8 +700,7 @@ static int _parse_message(struct dm_event_daemon_message *msg, char **dso_name, return 0; } - if (id) - dm_free(id); + dm_free(id); return -ENOMEM; } @@ -863,12 +862,13 @@ int dm_event_get_timeout(const char *device_path, uint32_t *timeout) if (!p) { log_error("malformed reply from dmeventd '%s'\n", msg.data); + dm_free(msg.data); return -EIO; } *timeout = atoi(p); } - if (msg.data) - dm_free(msg.data); + dm_free(msg.data); + return ret; } #endif diff --git a/lib/cache/lvmetad.c b/lib/cache/lvmetad.c index cc512589a..040a790ce 100644 --- a/lib/cache/lvmetad.c +++ b/lib/cache/lvmetad.c @@ -114,8 +114,7 @@ void lvmetad_set_token(const struct dm_config_value *filter) { int ft = 0; - if (_lvmetad_token) - dm_free(_lvmetad_token); + dm_free(_lvmetad_token); while (filter && filter->type == DM_CFG_STRING) { ft = calc_crc(ft, (const uint8_t *) filter->v.str, strlen(filter->v.str)); diff --git a/lib/format_text/format-text.c b/lib/format_text/format-text.c index 29df5f116..a6525903a 100644 --- a/lib/format_text/format-text.c +++ b/lib/format_text/format-text.c @@ -677,10 +677,8 @@ static int _vg_write_raw(struct format_instance *fid, struct volume_group *vg, if (!dev_close(mdac->area.dev)) stack; - if (fidtc->raw_metadata_buf) { - dm_free(fidtc->raw_metadata_buf); - fidtc->raw_metadata_buf = NULL; - } + dm_free(fidtc->raw_metadata_buf); + fidtc->raw_metadata_buf = NULL; } return r; @@ -766,10 +764,9 @@ static int _vg_commit_raw_rlocn(struct format_instance *fid, if (!precommit) { if (!dev_close(mdac->area.dev)) stack; - if (fidtc->raw_metadata_buf) { - dm_free(fidtc->raw_metadata_buf); - fidtc->raw_metadata_buf = NULL; - } + + dm_free(fidtc->raw_metadata_buf); + fidtc->raw_metadata_buf = NULL; } return r; diff --git a/tools/pvscan.c b/tools/pvscan.c index 9e5536ede..724ae5f04 100644 --- a/tools/pvscan.c +++ b/tools/pvscan.c @@ -169,15 +169,13 @@ static int _clear_dev_from_lvmetad_cache(dev_t devno, int32_t major, int32_t min if (!dm_asprintf(&buf, "%" PRIi32 ":%" PRIi32, major, minor)) stack; if (!lvmetad_pv_gone(devno, buf ? : "", handler)) { - if (buf) - dm_free(buf); + dm_free(buf); return 0; } log_print_unless_silent("Device %s not found. " "Cleared from lvmetad cache.", buf ? : ""); - if (buf) - dm_free(buf); + dm_free(buf); return 1; }