|
|
afff29 |
From acf9aa0dce71106f3603398a7b6984ff91dd0eda Mon Sep 17 00:00:00 2001
|
|
|
afff29 |
From: Cathy Avery <cavery@redhat.com>
|
|
|
afff29 |
Date: Tue, 3 Dec 2019 14:30:50 +0100
|
|
|
afff29 |
Subject: [PATCH 4/4] Fix a resource leak issue in deployPkg
|
|
|
afff29 |
|
|
|
afff29 |
RH-Author: Cathy Avery <cavery@redhat.com>
|
|
|
afff29 |
Message-id: <20191203143050.23065-5-cavery@redhat.com>
|
|
|
afff29 |
Patchwork-id: 92837
|
|
|
afff29 |
O-Subject: [RHEL8.2 open-vm-tools PATCH 4/4] Fix a resource leak issue in deployPkg
|
|
|
afff29 |
Bugzilla: 1769881
|
|
|
afff29 |
RH-Acked-by: Vitaly Kuznetsov <vkuznets@redhat.com>
|
|
|
afff29 |
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
|
|
|
afff29 |
|
|
|
afff29 |
commit 2ffd2913088505d8249fa342b0ee8e5002a69108
|
|
|
afff29 |
Author: Oliver Kurth <okurth@vmware.com>
|
|
|
afff29 |
Date: Fri Nov 22 14:52:35 2019 -0800
|
|
|
afff29 |
|
|
|
afff29 |
Fix a resource leak issue in deployPkg
|
|
|
afff29 |
|
|
|
afff29 |
Variable file going out of scope in error path leaks the storage it
|
|
|
afff29 |
points to. Added fclose before return when malloc failed.
|
|
|
afff29 |
|
|
|
afff29 |
Signed-off-by: Cathy Avery <cavery@redhat.com>
|
|
|
afff29 |
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
|
|
|
afff29 |
---
|
|
|
afff29 |
open-vm-tools/libDeployPkg/linuxDeployment.c | 23 ++++++++++++++---------
|
|
|
afff29 |
1 file changed, 14 insertions(+), 9 deletions(-)
|
|
|
afff29 |
|
|
|
afff29 |
diff --git a/open-vm-tools/libDeployPkg/linuxDeployment.c b/open-vm-tools/libDeployPkg/linuxDeployment.c
|
|
|
afff29 |
index 1af0893..4f36a00 100644
|
|
|
afff29 |
--- a/open-vm-tools/libDeployPkg/linuxDeployment.c
|
|
|
afff29 |
+++ b/open-vm-tools/libDeployPkg/linuxDeployment.c
|
|
|
afff29 |
@@ -824,17 +824,18 @@ TransitionState(const char* stateFrom, const char* stateTo)
|
|
|
afff29 |
*
|
|
|
afff29 |
*-----------------------------------------------------------------------------
|
|
|
afff29 |
*/
|
|
|
afff29 |
-static char*
|
|
|
afff29 |
-GetNicsToEnable(const char* dir)
|
|
|
afff29 |
+
|
|
|
afff29 |
+static char *
|
|
|
afff29 |
+GetNicsToEnable(const char *dir)
|
|
|
afff29 |
{
|
|
|
afff29 |
/*
|
|
|
afff29 |
- * The file nics.txt will list ordinal number of all nics to enable separated by
|
|
|
afff29 |
- * a ",". In current architecture we can have max 4 nics. So we just have to read
|
|
|
afff29 |
- * maximum of 7 characters. This code uses 1024 chars to make sure any future
|
|
|
afff29 |
- * needs are accomodated.
|
|
|
afff29 |
+ * The file nics.txt will list ordinal number of all nics to enable separated
|
|
|
afff29 |
+ * by a ",". In current architecture we can have max 4 nics. So we just have
|
|
|
afff29 |
+ * to read maximum of 7 characters. This code uses 1024 chars to make sure
|
|
|
afff29 |
+ * any future needs are accomodated.
|
|
|
afff29 |
*/
|
|
|
afff29 |
static const unsigned int NICS_SIZE = 1024;
|
|
|
afff29 |
- static const char* nicFile = "/nics.txt";
|
|
|
afff29 |
+ static const char *nicFile = "/nics.txt";
|
|
|
afff29 |
|
|
|
afff29 |
FILE *file;
|
|
|
afff29 |
|
|
|
afff29 |
@@ -852,7 +853,9 @@ GetNicsToEnable(const char* dir)
|
|
|
afff29 |
if (file) {
|
|
|
afff29 |
ret = malloc(NICS_SIZE);
|
|
|
afff29 |
if (ret == NULL) {
|
|
|
afff29 |
- SetDeployError("Error allocating memory to read nic file '%s'", fileName);
|
|
|
afff29 |
+ SetDeployError("Error allocating memory to read nic file '%s'",
|
|
|
afff29 |
+ fileName);
|
|
|
afff29 |
+ fclose(file);
|
|
|
afff29 |
free(fileName);
|
|
|
afff29 |
return ret;
|
|
|
afff29 |
}
|
|
|
afff29 |
@@ -862,7 +865,8 @@ GetNicsToEnable(const char* dir)
|
|
|
afff29 |
|
|
|
afff29 |
// Check various error condition
|
|
|
afff29 |
if (ferror(file)) {
|
|
|
afff29 |
- SetDeployError("Error reading nic file '%s'.(%s)", fileName, strerror(errno));
|
|
|
afff29 |
+ SetDeployError("Error reading nic file '%s'.(%s)", fileName,
|
|
|
afff29 |
+ strerror(errno));
|
|
|
afff29 |
free(ret);
|
|
|
afff29 |
ret = NULL;
|
|
|
afff29 |
}
|
|
|
afff29 |
@@ -880,6 +884,7 @@ GetNicsToEnable(const char* dir)
|
|
|
afff29 |
return ret;
|
|
|
afff29 |
}
|
|
|
afff29 |
|
|
|
afff29 |
+
|
|
|
afff29 |
/**
|
|
|
afff29 |
*------------------------------------------------------------------------------
|
|
|
afff29 |
*
|
|
|
afff29 |
--
|
|
|
afff29 |
1.8.3.1
|
|
|
afff29 |
|