|
|
6b53ca |
From 95800c144d2ab2af95cdc8f08df0518c496a579a Mon Sep 17 00:00:00 2001
|
|
|
6b53ca |
From: Cathy Avery <cavery@redhat.com>
|
|
|
6b53ca |
Date: Thu, 12 Nov 2020 09:01:08 -0500
|
|
|
6b53ca |
Subject: [PATCH] Fix memory leaks.
|
|
|
6b53ca |
|
|
|
6b53ca |
RH-Author: Cathy Avery (cavery)
|
|
|
6b53ca |
RH-MergeRequest: 2: Fix memory leaks.
|
|
|
6b53ca |
RH-Commit: [1/1] 79ac85f5e8c31cc48b7b0834682c6320afcc2288 (cavery/open-vm-tools)
|
|
|
6b53ca |
RH-Bugzilla: 1896804
|
|
|
6b53ca |
|
|
|
6b53ca |
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1896804
|
|
|
6b53ca |
Brew: https://brewweb.engineering.redhat.com/brew/taskinfo?taskID=33050983
|
|
|
6b53ca |
Tested: By QE
|
|
|
6b53ca |
Upstream Status: devel branch
|
|
|
6b53ca |
|
|
|
6b53ca |
A Coverity scan of open-vm-tools reported a number of memory leaks
|
|
|
6b53ca |
on error code paths. Fix seven reported leaks, and modify code
|
|
|
6b53ca |
to address two false positives in order to make the code clearer
|
|
|
6b53ca |
and/or keep Coverity from reporting the issues. Also fix additional
|
|
|
6b53ca |
leaks found in the routine Proto_TextContents during code review.
|
|
|
6b53ca |
|
|
|
6b53ca |
(cherry picked from commit e18e67f727d0354b08a55b685178fd05f542c6da)
|
|
|
6b53ca |
Signed-off-by: Cathy Avery <cavery@redhat.com>
|
|
|
6b53ca |
---
|
|
|
6b53ca |
open-vm-tools/libvmtools/vmtoolsLog.c | 6 ++---
|
|
|
6b53ca |
.../plugins/guestInfo/guestInfoServer.c | 2 +-
|
|
|
6b53ca |
open-vm-tools/services/vmtoolsd/pluginMgr.c | 1 +
|
|
|
6b53ca |
open-vm-tools/vgauth/lib/proto.c | 23 +++++++++++++++----
|
|
|
6b53ca |
open-vm-tools/vgauth/serviceImpl/alias.c | 4 ++++
|
|
|
6b53ca |
5 files changed, 28 insertions(+), 8 deletions(-)
|
|
|
6b53ca |
|
|
|
6b53ca |
diff --git a/open-vm-tools/libvmtools/vmtoolsLog.c b/open-vm-tools/libvmtools/vmtoolsLog.c
|
|
|
6b53ca |
index a991b49f..bea5abd4 100644
|
|
|
6b53ca |
--- a/open-vm-tools/libvmtools/vmtoolsLog.c
|
|
|
6b53ca |
+++ b/open-vm-tools/libvmtools/vmtoolsLog.c
|
|
|
6b53ca |
@@ -2395,7 +2395,6 @@ VMTools_ChangeLogFilePath(const gchar *delimiter, // IN
|
|
|
6b53ca |
{
|
|
|
6b53ca |
gchar key[128];
|
|
|
6b53ca |
gchar *path = NULL;
|
|
|
6b53ca |
- gchar *userLogTemp = NULL;
|
|
|
6b53ca |
gchar **tokens;
|
|
|
6b53ca |
gboolean retVal = FALSE;
|
|
|
6b53ca |
|
|
|
6b53ca |
@@ -2412,8 +2411,9 @@ VMTools_ChangeLogFilePath(const gchar *delimiter, // IN
|
|
|
6b53ca |
|
|
|
6b53ca |
tokens = g_strsplit(path, delimiter, 2);
|
|
|
6b53ca |
if (tokens != NULL && *tokens != NULL){
|
|
|
6b53ca |
- userLogTemp = g_strjoin(appendString, *tokens, " ", NULL);
|
|
|
6b53ca |
- userLogTemp = g_strchomp (userLogTemp);
|
|
|
6b53ca |
+ char *userLogTemp = g_strjoin(appendString, *tokens, " ", NULL);
|
|
|
6b53ca |
+
|
|
|
6b53ca |
+ g_strchomp(userLogTemp);
|
|
|
6b53ca |
if (*(tokens+1) != NULL){
|
|
|
6b53ca |
gchar *userLog;
|
|
|
6b53ca |
userLog = g_strjoin(delimiter, userLogTemp, *(tokens+1), NULL);
|
|
|
6b53ca |
diff --git a/open-vm-tools/services/plugins/guestInfo/guestInfoServer.c b/open-vm-tools/services/plugins/guestInfo/guestInfoServer.c
|
|
|
6b53ca |
index c1ab6962..ab6725fe 100644
|
|
|
6b53ca |
--- a/open-vm-tools/services/plugins/guestInfo/guestInfoServer.c
|
|
|
6b53ca |
+++ b/open-vm-tools/services/plugins/guestInfo/guestInfoServer.c
|
|
|
6b53ca |
@@ -1298,12 +1298,12 @@ GuestInfoSendDiskInfoV1(ToolsAppCtx *ctx, // IN
|
|
|
6b53ca |
b64name,
|
|
|
6b53ca |
pdi->partitionList[i].freeBytes,
|
|
|
6b53ca |
pdi->partitionList[i].totalBytes);
|
|
|
6b53ca |
+ g_free(b64name);
|
|
|
6b53ca |
if (len <= 0) {
|
|
|
6b53ca |
goto exit;
|
|
|
6b53ca |
}
|
|
|
6b53ca |
|
|
|
6b53ca |
DynBuf_Append(&dynBuffer, tmpBuf, len);
|
|
|
6b53ca |
- g_free(b64name);
|
|
|
6b53ca |
|
|
|
6b53ca |
if (pdi->partitionList[i].fsType[0] != '\0') {
|
|
|
6b53ca |
len = Str_Snprintf(tmpBuf, sizeof tmpBuf, jsonPerDiskFsTypeFmt,
|
|
|
6b53ca |
diff --git a/open-vm-tools/services/vmtoolsd/pluginMgr.c b/open-vm-tools/services/vmtoolsd/pluginMgr.c
|
|
|
6b53ca |
index 53b91f7a..d5f2c0ef 100644
|
|
|
6b53ca |
--- a/open-vm-tools/services/vmtoolsd/pluginMgr.c
|
|
|
6b53ca |
+++ b/open-vm-tools/services/vmtoolsd/pluginMgr.c
|
|
|
6b53ca |
@@ -512,6 +512,7 @@ ToolsCoreLoadDirectory(ToolsAppCtx *ctx,
|
|
|
6b53ca |
dir = g_dir_open(pluginPath, 0, &err;;
|
|
|
6b53ca |
if (dir == NULL) {
|
|
|
6b53ca |
g_warning("Error opening dir: %s\n", err->message);
|
|
|
6b53ca |
+ g_clear_error(&err;;
|
|
|
6b53ca |
goto exit;
|
|
|
6b53ca |
}
|
|
|
6b53ca |
|
|
|
6b53ca |
diff --git a/open-vm-tools/vgauth/lib/proto.c b/open-vm-tools/vgauth/lib/proto.c
|
|
|
6b53ca |
index 12386918..01df9df7 100644
|
|
|
6b53ca |
--- a/open-vm-tools/vgauth/lib/proto.c
|
|
|
6b53ca |
+++ b/open-vm-tools/vgauth/lib/proto.c
|
|
|
6b53ca |
@@ -830,8 +830,10 @@ Proto_TextContents(GMarkupParseContext *parseContext,
|
|
|
6b53ca |
g_set_error(error, G_MARKUP_ERROR_PARSE, VGAUTH_E_INVALID_ARGUMENT,
|
|
|
6b53ca |
"Found pipeName in reply type %d",
|
|
|
6b53ca |
reply->expectedReplyType);
|
|
|
6b53ca |
+ g_free(val);
|
|
|
6b53ca |
+ } else {
|
|
|
6b53ca |
+ reply->replyData.sessionReq.pipeName = val;
|
|
|
6b53ca |
}
|
|
|
6b53ca |
- reply->replyData.sessionReq.pipeName = val;
|
|
|
6b53ca |
break;
|
|
|
6b53ca |
|
|
|
6b53ca |
case PARSE_STATE_TICKET:
|
|
|
6b53ca |
@@ -839,8 +841,10 @@ Proto_TextContents(GMarkupParseContext *parseContext,
|
|
|
6b53ca |
g_set_error(error, G_MARKUP_ERROR_PARSE, VGAUTH_E_INVALID_ARGUMENT,
|
|
|
6b53ca |
"Found ticket in reply type %d",
|
|
|
6b53ca |
reply->expectedReplyType);
|
|
|
6b53ca |
+ g_free(val);
|
|
|
6b53ca |
+ } else {
|
|
|
6b53ca |
+ reply->replyData.createTicket.ticket = val;
|
|
|
6b53ca |
}
|
|
|
6b53ca |
- reply->replyData.createTicket.ticket = val;
|
|
|
6b53ca |
break;
|
|
|
6b53ca |
|
|
|
6b53ca |
case PARSE_STATE_TOKEN:
|
|
|
6b53ca |
@@ -853,6 +857,7 @@ Proto_TextContents(GMarkupParseContext *parseContext,
|
|
|
6b53ca |
g_set_error(error, G_MARKUP_ERROR_PARSE, VGAUTH_E_INVALID_ARGUMENT,
|
|
|
6b53ca |
"Found token in reply type %d",
|
|
|
6b53ca |
reply->expectedReplyType);
|
|
|
6b53ca |
+ g_free(val);
|
|
|
6b53ca |
}
|
|
|
6b53ca |
break;
|
|
|
6b53ca |
|
|
|
6b53ca |
@@ -863,6 +868,7 @@ Proto_TextContents(GMarkupParseContext *parseContext,
|
|
|
6b53ca |
g_set_error(error, G_MARKUP_ERROR_PARSE, VGAUTH_E_INVALID_ARGUMENT,
|
|
|
6b53ca |
"Found token in reply type %d",
|
|
|
6b53ca |
reply->expectedReplyType);
|
|
|
6b53ca |
+ g_free(val);
|
|
|
6b53ca |
}
|
|
|
6b53ca |
break;
|
|
|
6b53ca |
|
|
|
6b53ca |
@@ -878,6 +884,7 @@ Proto_TextContents(GMarkupParseContext *parseContext,
|
|
|
6b53ca |
g_set_error(error, G_MARKUP_ERROR_PARSE, VGAUTH_E_INVALID_ARGUMENT,
|
|
|
6b53ca |
"Found username in reply type %d",
|
|
|
6b53ca |
reply->expectedReplyType);
|
|
|
6b53ca |
+ g_free(val);
|
|
|
6b53ca |
}
|
|
|
6b53ca |
break;
|
|
|
6b53ca |
|
|
|
6b53ca |
@@ -890,6 +897,7 @@ Proto_TextContents(GMarkupParseContext *parseContext,
|
|
|
6b53ca |
g_set_error(error, G_MARKUP_ERROR_PARSE, VGAUTH_E_INVALID_ARGUMENT,
|
|
|
6b53ca |
"Found pemCert in reply type %d",
|
|
|
6b53ca |
reply->expectedReplyType);
|
|
|
6b53ca |
+ g_free(val);
|
|
|
6b53ca |
}
|
|
|
6b53ca |
break;
|
|
|
6b53ca |
case PARSE_STATE_CERTCOMMENT:
|
|
|
6b53ca |
@@ -899,6 +907,7 @@ Proto_TextContents(GMarkupParseContext *parseContext,
|
|
|
6b53ca |
g_set_error(error, G_MARKUP_ERROR_PARSE, VGAUTH_E_INVALID_ARGUMENT,
|
|
|
6b53ca |
"Found cert comment in reply type %d",
|
|
|
6b53ca |
reply->expectedReplyType);
|
|
|
6b53ca |
+ g_free(val);
|
|
|
6b53ca |
}
|
|
|
6b53ca |
break;
|
|
|
6b53ca |
|
|
|
6b53ca |
@@ -923,6 +932,7 @@ Proto_TextContents(GMarkupParseContext *parseContext,
|
|
|
6b53ca |
g_set_error(error, G_MARKUP_ERROR_PARSE, VGAUTH_E_INVALID_ARGUMENT,
|
|
|
6b53ca |
"Found SAMLSubject in reply type %d",
|
|
|
6b53ca |
reply->expectedReplyType);
|
|
|
6b53ca |
+ g_free(val);
|
|
|
6b53ca |
}
|
|
|
6b53ca |
break;
|
|
|
6b53ca |
case PARSE_STATE_USERHANDLETYPE:
|
|
|
6b53ca |
@@ -968,6 +978,7 @@ Proto_TextContents(GMarkupParseContext *parseContext,
|
|
|
6b53ca |
g_set_error(error, G_MARKUP_ERROR_PARSE, VGAUTH_E_INVALID_ARGUMENT,
|
|
|
6b53ca |
"Found NamedSubject in reply type %d",
|
|
|
6b53ca |
reply->expectedReplyType);
|
|
|
6b53ca |
+ g_free(val);
|
|
|
6b53ca |
}
|
|
|
6b53ca |
break;
|
|
|
6b53ca |
case PARSE_STATE_ANYSUBJECT:
|
|
|
6b53ca |
@@ -990,6 +1001,7 @@ Proto_TextContents(GMarkupParseContext *parseContext,
|
|
|
6b53ca |
"Found AnySubject in reply type %d",
|
|
|
6b53ca |
reply->expectedReplyType);
|
|
|
6b53ca |
}
|
|
|
6b53ca |
+ g_free(val);
|
|
|
6b53ca |
break;
|
|
|
6b53ca |
case PARSE_STATE_COMMENT:
|
|
|
6b53ca |
if (PROTO_REPLY_QUERYALIASES == reply->expectedReplyType) {
|
|
|
6b53ca |
@@ -1005,11 +1017,13 @@ Proto_TextContents(GMarkupParseContext *parseContext,
|
|
|
6b53ca |
g_set_error(error, G_MARKUP_ERROR_PARSE, VGAUTH_E_INVALID_ARGUMENT,
|
|
|
6b53ca |
"Found comment in reply type %d",
|
|
|
6b53ca |
reply->expectedReplyType);
|
|
|
6b53ca |
+ g_free(val);
|
|
|
6b53ca |
}
|
|
|
6b53ca |
break;
|
|
|
6b53ca |
default:
|
|
|
6b53ca |
g_warning("Unexpected value '%s' in unhandled parseState %d in %s\n",
|
|
|
6b53ca |
val, reply->parseState, __FUNCTION__);
|
|
|
6b53ca |
+ g_free(val);
|
|
|
6b53ca |
ASSERT(0);
|
|
|
6b53ca |
}
|
|
|
6b53ca |
}
|
|
|
6b53ca |
@@ -1200,7 +1214,6 @@ VGAuth_ReadAndParseResponse(VGAuthContext *ctx,
|
|
|
6b53ca |
VGAuthError err = VGAUTH_E_OK;
|
|
|
6b53ca |
GMarkupParseContext *parseContext;
|
|
|
6b53ca |
gsize len;
|
|
|
6b53ca |
- gchar *rawReply = NULL;
|
|
|
6b53ca |
ProtoReply *reply;
|
|
|
6b53ca |
gboolean bRet;
|
|
|
6b53ca |
GError *gErr = NULL;
|
|
|
6b53ca |
@@ -1217,6 +1230,8 @@ VGAuth_ReadAndParseResponse(VGAuthContext *ctx,
|
|
|
6b53ca |
* transport.
|
|
|
6b53ca |
*/
|
|
|
6b53ca |
while (!reply->complete) {
|
|
|
6b53ca |
+ gchar *rawReply = NULL;
|
|
|
6b53ca |
+
|
|
|
6b53ca |
err = VGAuth_CommReadData(ctx, &len, &rawReply);
|
|
|
6b53ca |
if (0 == len) { // EOF -- not expected
|
|
|
6b53ca |
err = VGAUTH_E_COMM;
|
|
|
6b53ca |
@@ -1237,6 +1252,7 @@ VGAuth_ReadAndParseResponse(VGAuthContext *ctx,
|
|
|
6b53ca |
rawReply,
|
|
|
6b53ca |
len,
|
|
|
6b53ca |
&gErr);
|
|
|
6b53ca |
+ g_free(rawReply);
|
|
|
6b53ca |
if (!bRet) {
|
|
|
6b53ca |
/*
|
|
|
6b53ca |
* XXX Could drain the wire here, but since this should
|
|
|
6b53ca |
@@ -1252,7 +1268,6 @@ VGAuth_ReadAndParseResponse(VGAuthContext *ctx,
|
|
|
6b53ca |
* XXX need some way to break out if packet never completed
|
|
|
6b53ca |
* yet socket left valid. timer?
|
|
|
6b53ca |
*/
|
|
|
6b53ca |
- g_free(rawReply);
|
|
|
6b53ca |
}
|
|
|
6b53ca |
|
|
|
6b53ca |
#if VGAUTH_PROTO_TRACE
|
|
|
6b53ca |
diff --git a/open-vm-tools/vgauth/serviceImpl/alias.c b/open-vm-tools/vgauth/serviceImpl/alias.c
|
|
|
6b53ca |
index f6cde02c..0a43811e 100644
|
|
|
6b53ca |
--- a/open-vm-tools/vgauth/serviceImpl/alias.c
|
|
|
6b53ca |
+++ b/open-vm-tools/vgauth/serviceImpl/alias.c
|
|
|
6b53ca |
@@ -3158,6 +3158,9 @@ ServiceIDVerifyStoreContents(void)
|
|
|
6b53ca |
* a blacklist of bad files and keep going. but that's
|
|
|
6b53ca |
* a lot of risky work that's very hard to test, so punt for now.
|
|
|
6b53ca |
*/
|
|
|
6b53ca |
+ g_free(badFileName);
|
|
|
6b53ca |
+ g_free(fullFileName);
|
|
|
6b53ca |
+ g_dir_close(dir);
|
|
|
6b53ca |
return VGAUTH_E_FAIL;
|
|
|
6b53ca |
} else {
|
|
|
6b53ca |
Audit_Event(TRUE,
|
|
|
6b53ca |
@@ -3408,6 +3411,7 @@ ServiceAliasInitAliasStore(void)
|
|
|
6b53ca |
"Failed to rename suspect Alias store directory '%s' to '%s'"),
|
|
|
6b53ca |
aliasStoreRootDir, badRootDirName);
|
|
|
6b53ca |
// XXX making this fatal for now. can we do anything better?
|
|
|
6b53ca |
+ g_free(badRootDirName);
|
|
|
6b53ca |
return VGAUTH_E_FAIL;
|
|
|
6b53ca |
}
|
|
|
6b53ca |
g_free(badRootDirName);
|
|
|
6b53ca |
--
|
|
|
6b53ca |
2.18.4
|
|
|
6b53ca |
|