From: Oliver Kurth Date: Mon, 3 Jun 2019 20:39:45 +0000 (-0700) Subject: Fix memory leak in SNEBuildHash function. X-Git-Tag: stable-11.0.0~56 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=61c51b4e4ac091f066e5e0efa22cc39d00b05d6d;p=thirdparty%2Fopen-vm-tools.git Fix memory leak in SNEBuildHash function. 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. --- diff --git a/open-vm-tools/lib/system/systemLinux.c b/open-vm-tools/lib/system/systemLinux.c index 7d9798ab7..c6f478027 100644 --- a/open-vm-tools/lib/system/systemLinux.c +++ b/open-vm-tools/lib/system/systemLinux.c @@ -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; + } } /*