summaryrefslogtreecommitdiff
path: root/tools/vgcfgbackup.c
diff options
context:
space:
mode:
authorZdenek Kabelac <zkabelac@redhat.com>2017-11-05 18:39:05 +0100
committerZdenek Kabelac <zkabelac@redhat.com>2017-11-07 21:26:09 +0100
commit56b527a6fbf6f886af4c78dd118867e4513c6a9c (patch)
tree1c199b45a974b9b13c1951c39b31bc100d02a7ae /tools/vgcfgbackup.c
parent14d0b0bbddb214fbb5dcacfb60d1723d87076bd9 (diff)
downloadlvm2-56b527a6fbf6f886af4c78dd118867e4513c6a9c.tar.gz
coverity: avoid memleak
When security_level was set, allocated filename was leaking.
Diffstat (limited to 'tools/vgcfgbackup.c')
-rw-r--r--tools/vgcfgbackup.c13
1 files changed, 9 insertions, 4 deletions
diff --git a/tools/vgcfgbackup.c b/tools/vgcfgbackup.c
index 5d2113186..814ed1db6 100644
--- a/tools/vgcfgbackup.c
+++ b/tools/vgcfgbackup.c
@@ -20,8 +20,13 @@ static char *_expand_filename(const char *template, const char *vg_name,
{
char *filename;
- if (security_level())
- return dm_strdup(template);
+ if (security_level()) {
+ if (!(filename = dm_strdup(template))) {
+ log_error("Failed to allocate filename.");
+ return NULL;
+ }
+ goto out;
+ }
if (!(filename = dm_malloc(PATH_MAX))) {
log_error("Failed to allocate filename.");
@@ -31,7 +36,7 @@ static char *_expand_filename(const char *template, const char *vg_name,
if (dm_snprintf(filename, PATH_MAX, template, vg_name) < 0) {
log_error("Error processing filename template %s",
template);
- dm_free(filename);
+ dm_free(filename);
return NULL;
}
if (*last_filename && !strncmp(*last_filename, filename, PATH_MAX)) {
@@ -40,7 +45,7 @@ static char *_expand_filename(const char *template, const char *vg_name,
dm_free(filename);
return NULL;
}
-
+out:
dm_free(*last_filename);
*last_filename = filename;