Skip to contentSkip to conversation

evmctl: fix memory leak in get_password

PATCH Superseded Bruno Meneguele 1 participant 2 messages Aug 16, 2021 Keys-trusted

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 evmctl: fix memory leak in get_password

The variable "password" is not freed nor returned in case get_password() succeeds. Return it instead of the intermediary variable "pwd". Issue found by Coverity scan tool.

src/evmctl.c:2565: leaked_storage: Variable "password" going out of scope
leaks the storage it points to.

---
Changelog:
v1: instead of removing the 'pwd' var, return 'password' (Mimi)

 src/evmctl.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
src/evmctl.c +6 -1
index a8065bbe124a..ab7173723095 100644
@@ -2625,7 +2625,12 @@ static char *get_password(void)
 		return NULL;
 	}
 
-	return pwd;
+	if (pwd == NULL) {
+		free(password);
+		return NULL;
+	}
+
+	return password;
 }
 
 int main(int argc, char *argv[])
Signature · 1 line
2.31.1
#1 lore raw

PATCH v2 1/1 evmctl: fix memory leak in get_password

The variable "password" is not freed nor returned in case get_password() succeeds. Return it instead of the intermediary variable "pwd". Issue found by Coverity scan tool.

src/evmctl.c:2565: leaked_storage: Variable "password" going out of scope
leaks the storage it points to.

---
Changelog:
v1: instead of removing the 'pwd' var, return 'password' (Mimi)

 src/evmctl.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
src/evmctl.c +6 -1
index a8065bbe124a..ab7173723095 100644
@@ -2625,7 +2625,12 @@ static char *get_password(void)
 		return NULL;
 	}
 
-	return pwd;
+	if (pwd == NULL) {
+		free(password);
+		return NULL;
+	}
+
+	return password;
 }
 
 int main(int argc, char *argv[])
Signature · 1 line
2.31.1