]> git.ipfire.org Git - thirdparty/open-vm-tools.git/commitdiff
Fix a resource leak issue in deployPkg
authorOliver Kurth <okurth@vmware.com>
Fri, 22 Nov 2019 22:52:35 +0000 (14:52 -0800)
committerOliver Kurth <okurth@vmware.com>
Fri, 22 Nov 2019 22:52:35 +0000 (14:52 -0800)
Variable file going out of scope in error path leaks the storage it
points to.  Added fclose before return when malloc failed.

open-vm-tools/libDeployPkg/linuxDeployment.c

index 9a64cff70786282259d33add26d1eaf6e403bd36..3a3b679283943bf4d7ab9f8bcbefde449ca0801c 100644 (file)
@@ -834,17 +834,18 @@ TransitionState(const char* stateFrom, const char* stateTo)
  *
  *-----------------------------------------------------------------------------
  */
-static char*
-GetNicsToEnable(const char* dir)
+
+static char *
+GetNicsToEnable(const char *dir)
 {
    /*
-    * The file nics.txt will list ordinal number of all nics to enable separated by
-    * a ",". In current architecture we can have max 4 nics. So we just have to read
-    * maximum of 7 characters. This code uses 1024 chars to make sure any future
-    * needs are accomodated.
+    * The file nics.txt will list ordinal number of all nics to enable separated
+    * by a ",". In current architecture we can have max 4 nics. So we just have
+    * to read maximum of 7 characters. This code uses 1024 chars to make sure
+    * any future needs are accomodated.
     */
    static const unsigned int NICS_SIZE = 1024;
-   static const charnicFile = "/nics.txt";
+   static const char *nicFile = "/nics.txt";
 
    FILE *file;
 
@@ -862,7 +863,9 @@ GetNicsToEnable(const char* dir)
    if (file) {
       ret = malloc(NICS_SIZE);
       if (ret == NULL) {
-         SetDeployError("Error allocating memory to read nic file '%s'", fileName);
+         SetDeployError("Error allocating memory to read nic file '%s'",
+                        fileName);
+         fclose(file);
          free(fileName);
          return ret;
       }
@@ -872,7 +875,8 @@ GetNicsToEnable(const char* dir)
 
       // Check various error condition
       if (ferror(file)) {
-         SetDeployError("Error reading nic file '%s'.(%s)", fileName, strerror(errno));
+         SetDeployError("Error reading nic file '%s'.(%s)", fileName,
+                        strerror(errno));
          free(ret);
          ret = NULL;
       }
@@ -890,6 +894,7 @@ GetNicsToEnable(const char* dir)
    return ret;
 }
 
+
 /**
  *------------------------------------------------------------------------------
  *