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