[Debian-ha-commits] [ocfs2-tools] 02/58: ocfs2_hb_ctl: Fix memory leak problems in main

Valentin Vidic vvidic-guest at moszumanska.debian.org
Tue Jun 20 13:40:39 UTC 2017


This is an automated email from the git hooks/post-receive script.

vvidic-guest pushed a commit to branch upstream
in repository ocfs2-tools.

commit 31224fa8eb238dd679ef1d6a047c6ea5e8322b62
Author: Jun Piao <piaojun at huawei.com>
Date:   Mon Jun 6 21:59:19 2016 +0800

    ocfs2_hb_ctl: Fix memory leak problems in main
    
    In main, hbo.dev_str, hbo.service and hbo.uuid_str should be freed after
    use.
    
    Signed-off-by: Jun Piao <piaojun at huawei.com>
    [Joseph: check the return value of strdup]
    Signed-off-by: Joseph Qi <joseph.qi at huawei.com>
---
 ocfs2_hb_ctl/ocfs2_hb_ctl.c | 16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)

diff --git a/ocfs2_hb_ctl/ocfs2_hb_ctl.c b/ocfs2_hb_ctl/ocfs2_hb_ctl.c
index e4daa92..270fb6b 100644
--- a/ocfs2_hb_ctl/ocfs2_hb_ctl.c
+++ b/ocfs2_hb_ctl/ocfs2_hb_ctl.c
@@ -171,13 +171,16 @@ out:
 	return err;
 }
 
-static errcode_t get_uuid(char *dev, char *uuid)
+static errcode_t get_uuid(char *dev, char **uuid)
 {
 	errcode_t ret;
 
 	ret = get_desc(dev);
-	if (!ret) 
-		strcpy(uuid, region_desc->r_name);
+	if (!ret) {
+		*uuid = strdup(region_desc->r_name);
+		if (!*uuid)
+			ret = OCFS2_ET_NO_MEMORY;
+	}
 
 	return ret;
 }
@@ -543,7 +546,7 @@ int main(int argc, char **argv)
 	struct hb_ctl_options hbo = {
 		.action = HB_ACTION_UNKNOWN,
 	};
-	char hbuuid[33];
+	char *hbuuid = NULL;
 
 	setbuf(stdout, NULL);
 	setbuf(stderr, NULL);
@@ -577,7 +580,7 @@ int main(int argc, char **argv)
 	}
 
 	if (!hbo.uuid_str) {
-		err = get_uuid(hbo.dev_str, hbuuid);
+		err = get_uuid(hbo.dev_str, &hbuuid);
 		if (err) {
 			com_err(progname, err, "while reading uuid");
 			ret = -EINVAL;
@@ -631,6 +634,9 @@ int main(int argc, char **argv)
 	block_signals(SIG_UNBLOCK);
 
 bail:
+	ocfs2_free(&hbo.dev_str);
+	ocfs2_free(&hbo.service);
+	ocfs2_free(&hbo.uuid_str);
 	free_desc();
 	return ret ? 1 : 0;
 }

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-ha/ocfs2-tools.git



More information about the Debian-HA-Commits mailing list