[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 3/5] Fix memory leak of char* ecmd in pk_cmd_exec
From: |
Dan Čermák |
Subject: |
[PATCH 3/5] Fix memory leak of char* ecmd in pk_cmd_exec |
Date: |
Tue, 17 Dec 2019 00:45:01 +0100 |
From: Dan Čermák <address@hidden>
---
src/pk-cmd.c | 20 ++++++++++++--------
1 file changed, 12 insertions(+), 8 deletions(-)
diff --git a/src/pk-cmd.c b/src/pk-cmd.c
index a8cff03..fbaa959 100644
--- a/src/pk-cmd.c
+++ b/src/pk-cmd.c
@@ -615,6 +615,7 @@ pk_cmd_exec (char *str)
char *ecmd, *end;
pvm_val val;
int what; /* 0 -> declaration, 1 -> statement */
+ int retval = 1;
ecmd = xmalloc (strlen (cmd) + 2);
strcpy (ecmd, cmd);
@@ -640,14 +641,18 @@ pk_cmd_exec (char *str)
if (what == 0)
{
/* Declaration. */
- if (!pkl_compile_buffer (poke_compiler, ecmd, &end))
- goto error;
+ if (!pkl_compile_buffer (poke_compiler, ecmd, &end)) {
+ retval = 0;
+ goto cleanup;
+ }
}
else
{
/* Statement. */
- if (!pkl_compile_statement (poke_compiler, ecmd, &end, &val))
- goto error;
+ if (!pkl_compile_statement (poke_compiler, ecmd, &end, &val)) {
+ retval = 0;
+ goto cleanup;
+ }
if (val != PVM_NULL)
{
@@ -656,10 +661,9 @@ pk_cmd_exec (char *str)
}
}
- return 1;
-
- error:
- return 0;
+ cleanup:
+ free(ecmd);
+ return retval;
}
}
--
2.23.0