[lxc-devel] [lxc/master] storage: prevent unitialized variable warning
brauner on Github
lxc-bot at linuxcontainers.org
Sun Apr 14 13:47:39 UTC 2019
A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 489 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20190414/6f4bfbd9/attachment.bin>
-------------- next part --------------
From 240a130f67006b3e5dcbf0df0be383617d6dba03 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Sun, 14 Apr 2019 15:46:12 +0200
Subject: [PATCH] storage: prevent unitialized variable warning
We can simply fix this issue by switching to our cleanup macros instead of
manually freeing the memory.
Closes #2912.
Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
src/lxc/storage/btrfs.c | 11 +++--------
1 file changed, 3 insertions(+), 8 deletions(-)
diff --git a/src/lxc/storage/btrfs.c b/src/lxc/storage/btrfs.c
index d46ed0a53d..f16acc4cbb 100644
--- a/src/lxc/storage/btrfs.c
+++ b/src/lxc/storage/btrfs.c
@@ -41,6 +41,7 @@
#include "btrfs.h"
#include "config.h"
#include "log.h"
+#include "memory_utils.h"
#include "rsync.h"
#include "storage.h"
#include "utils.h"
@@ -763,7 +764,6 @@ static int btrfs_recursive_destroy(const char *path)
int ret, e, i;
unsigned long off = 0;
u16 name_len;
- char *tmppath;
u64 dir_id;
fd = open(path, O_RDONLY);
@@ -834,7 +834,8 @@ static int btrfs_recursive_destroy(const char *path)
* name of the child subvol in question.
*/
if (sh.objectid != root_id && sh.type == BTRFS_ROOT_BACKREF_KEY) {
- char *name, *tmp;
+ __do_free char *name = NULL, *tmppath = NULL;
+ char *tmp;
ref = (struct btrfs_root_ref *)(args.buf + off);
name_len = btrfs_stack_root_ref_name_len(ref);
@@ -844,7 +845,6 @@ static int btrfs_recursive_destroy(const char *path)
if (!name) {
ERROR("Out of memory");
free_btrfs_tree(tree);
- free(tmppath);
close(fd);
}
@@ -859,14 +859,9 @@ static int btrfs_recursive_destroy(const char *path)
name_len, tmppath)) {
ERROR("Out of memory");
free_btrfs_tree(tree);
- free(name);
- free(tmppath);
close(fd);
return -1;
}
-
- free(tmppath);
- free(name);
}
off += sh.len;
More information about the lxc-devel
mailing list