]> git.ipfire.org Git - thirdparty/open-vm-tools.git/commitdiff
lib/file: Fix a memory leak in FileLock_Lock.
authorOliver Kurth <okurth@vmware.com>
Tue, 26 May 2020 22:32:56 +0000 (15:32 -0700)
committerOliver Kurth <okurth@vmware.com>
Tue, 26 May 2020 22:32:56 +0000 (15:32 -0700)
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.

open-vm-tools/lib/file/fileLockPrimitive.c

index 4f0f7801dda12f6e953010a73e877c553e3ced4c..b83f391b80520ef8fa5a88a376a8374bb6e48347 100644 (file)
@@ -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,