Blame SOURCES/ovt-Fix-memory-leaks.patch

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