From f59163c46d3b2e6bf35bccbf2973dcf9a4ac61d5 Mon Sep 17 00:00:00 2001 From: Michal Privoznik Date: Wed, 5 Apr 2017 10:48:10 +0200 Subject: [PATCH] virISCSIGetSession: Don't leak memory This function runs an iscsi command and parses its output. However, due to the nature of things, virISCSIExtractSession() callback can be called multiple times. In each run it would allocate new memory and overwrite the variable where we keep pointer to it and thus leaking old allocations. Signed-off-by: Michal Privoznik (cherry picked from commit 9c037c6caea6155bad82eb3a204af68dcdaf7409) --- src/util/viriscsi.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/util/viriscsi.c b/src/util/viriscsi.c index 504ffbd14b..d4c745a1af 100644 --- a/src/util/viriscsi.c +++ b/src/util/viriscsi.c @@ -52,7 +52,8 @@ virISCSIExtractSession(char **const groups, { struct virISCSISessionData *data = opaque; - if (STREQ(groups[1], data->devpath)) + if (!data->session && + STREQ(groups[1], data->devpath)) return VIR_STRDUP(data->session, groups[0]); return 0; } -- 2.47.3