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