From: Oliver Kurth Date: Tue, 26 May 2020 22:32:56 +0000 (-0700) Subject: lib/file: Fix a memory leak in FileLock_Lock. X-Git-Tag: stable-11.2.0~213 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f01d92c41b756f0167308ef7b5596b0554a661b8;p=thirdparty%2Fopen-vm-tools.git lib/file: Fix a memory leak in FileLock_Lock. Valgrind complained about a minor leak within FileLock_Lock when running test-vmx Firmware.Efi.QuickBoot . FileLockScanner builds a list of "active locks" and traverses that list repeatedly, but whenever it decides to remove an entry from the list, it would simply leak it. This change ensures that the list item is not leaked by Posix_Free()ing it once it is no longer needed. --- diff --git a/open-vm-tools/lib/file/fileLockPrimitive.c b/open-vm-tools/lib/file/fileLockPrimitive.c index 4f0f7801d..b83f391b8 100644 --- a/open-vm-tools/lib/file/fileLockPrimitive.c +++ b/open-vm-tools/lib/file/fileLockPrimitive.c @@ -1,5 +1,5 @@ /********************************************************* - * Copyright (C) 2007-2019 VMware, Inc. All rights reserved. + * Copyright (C) 2007-2020 VMware, Inc. All rights reserved. * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published @@ -939,15 +939,21 @@ FileLockScanner(const char *lockDir, // IN: } if (remove) { + ActiveLock *temp = ptr; + + ptr = ptr->next; + Posix_Free(temp->dirName); + Posix_Free(temp); + if (prev == NULL) { - myValues->lockList = ptr->next; + myValues->lockList = ptr; } else { - prev->next = ptr->next; + prev->next = ptr; } + } else { + prev = ptr; + ptr = ptr->next; } - - prev = ptr; - ptr = ptr->next; } FileSleeper(FILELOCK_PROGRESS_SAMPLE,