diff mbox

[2/2] Btrfs-progs: fix possible memory leak related to subvolume/snapshot creation

Message ID 1372867658-4144-2-git-send-email-wangshilong1991@gmail.com (mailing list archive)
State Accepted, archived
Headers show

Commit Message

Wang Shilong July 3, 2013, 4:07 p.m. UTC
From: Wang Shilong <wangsl-fnst@cn.fujitsu.com>

The operation related qgroup inherit may fails, if it fails, we should
free memory allocated,otherwise, memory leak happens.

Signed-off-by: Wang Shilong <wangsl-fnst@cn.fujitsu.com>
---
 cmds-subvolume.c | 30 ++++++++++++++++++++----------
 1 file changed, 20 insertions(+), 10 deletions(-)
diff mbox

Patch

diff --git a/cmds-subvolume.c b/cmds-subvolume.c
index ccb4762..9db989e 100644
--- a/cmds-subvolume.c
+++ b/cmds-subvolume.c
@@ -89,13 +89,17 @@  static int cmd_subvol_create(int argc, char **argv)
 		switch (c) {
 		case 'c':
 			res = qgroup_inherit_add_copy(&inherit, optarg, 0);
-			if (res)
-				return res;
+			if (res) {
+				retval = res;
+				goto out;
+			}
 			break;
 		case 'i':
 			res = qgroup_inherit_add_group(&inherit, optarg);
-			if (res)
-				return res;
+			if (res) {
+				retval = res;
+				goto out;
+			}
 			break;
 		default:
 			usage(cmd_subvol_create_usage);
@@ -516,21 +520,27 @@  static int cmd_snapshot(int argc, char **argv)
 		switch (c) {
 		case 'c':
 			res = qgroup_inherit_add_copy(&inherit, optarg, 0);
-			if (res)
-				return res;
+			if (res) {
+				retval = res;
+				goto out;
+			}
 			break;
 		case 'i':
 			res = qgroup_inherit_add_group(&inherit, optarg);
-			if (res)
-				return res;
+			if (res) {
+				retval = res;
+				goto out;
+			}
 			break;
 		case 'r':
 			readonly = 1;
 			break;
 		case 'x':
 			res = qgroup_inherit_add_copy(&inherit, optarg, 1);
-			if (res)
-				return res;
+			if (res) {
+				retval = res;
+				goto out;
+			}
 			break;
 		default:
 			usage(cmd_snapshot_usage);