]> git.ipfire.org Git - thirdparty/open-vm-tools.git/commitdiff
Fix memory leak in SNEBuildHash function.
authorOliver Kurth <okurth@vmware.com>
Mon, 3 Jun 2019 20:39:45 +0000 (13:39 -0700)
committerOliver Kurth <okurth@vmware.com>
Mon, 3 Jun 2019 20:39:45 +0000 (13:39 -0700)
In a specific code path, if a key already exists in the hashtable,
the memory allocated for 'value' variable is not being freed.  This
leads to a memory leak.  Fixed.

open-vm-tools/lib/system/systemLinux.c

index 7d9798ab71b331f0f48c8fa9a2b6d6cd00d9989d..c6f4780279bfc22f6147b7ca6d216b5b89ff4fc4 100644 (file)
@@ -611,7 +611,15 @@ SNEBuildHash(const char **compatEnviron)
          value = NULL;
          HashTable_ReplaceOrInsert(environTable, realKey, realValue);
       } else {
-         HashTable_LookupOrInsert(environTable, key, value);
+         void *hashed = HashTable_LookupOrInsert(environTable, key, value);
+         if (hashed != value) {
+            /*
+             * The key already exists in the hashtable and its value was
+             * not replaced. We need to free the memory allocated for 'value'.
+             */
+            free(value);
+            value = NULL;
+         }
       }
 
       /*