[PATCH] cmd: Fix memory leak in WCMD_reduce.
Lauri Kenttä
lauri.kentta at gmail.com
Sat Dec 17 02:33:27 CST 2016
WCMD_reduce has another return point if *varstack is NULL, and it's
missing heap_free(thisop). However, I think a more proper fix is to
use WCMD_popoperator and avoid the heap_free in both cases.
Fixes bug 36162, I think.
Signed-off-by: Lauri Kenttä <lauri.kentta at gmail.com>
---
programs/cmd/builtins.c | 18 ++++++++----------
1 file changed, 8 insertions(+), 10 deletions(-)
diff --git a/programs/cmd/builtins.c b/programs/cmd/builtins.c
index cd319f8f0b..f3dbe3a2ed 100644
--- a/programs/cmd/builtins.c
+++ b/programs/cmd/builtins.c
@@ -3689,7 +3689,7 @@ static WCHAR WCMD_popoperator(OPSTACK **opstack) {
* Returns non-zero on error.
*/
static int WCMD_reduce(OPSTACK **opstack, VARSTACK **varstack) {
- OPSTACK *thisop;
+ WCHAR thisop;
int var1,var2;
int rc = 0;
@@ -3699,13 +3699,12 @@ static int WCMD_reduce(OPSTACK **opstack, VARSTACK **varstack) {
}
/* Remove the top operator */
- thisop = *opstack;
- *opstack = (*opstack)->next;
- WINE_TRACE("Reducing the stacks - processing operator %c\n", thisop->op);
+ thisop = WCMD_popoperator(opstack);
+ WINE_TRACE("Reducing the stacks - processing operator %c\n", thisop);
/* One variable operators */
var1 = WCMD_popnumber(varstack);
- switch (thisop->op) {
+ switch (thisop) {
case '!': WCMD_pushnumber(NULL, !var1, varstack);
break;
case '~': WCMD_pushnumber(NULL, ~var1, varstack);
@@ -3721,7 +3720,7 @@ static int WCMD_reduce(OPSTACK **opstack, VARSTACK **varstack) {
WINE_TRACE("No operands left for the reduce?\n");
return WCMD_NOOPERAND;
}
- switch (thisop->op) {
+ switch (thisop) {
case '!':
case '~':
case OP_POSITIVE:
@@ -3792,11 +3791,11 @@ static int WCMD_reduce(OPSTACK **opstack, VARSTACK **varstack) {
/* Make the operand stack grow by pushing the assign operator plus the
operator to perform */
while (calcassignments[i].op != ' ' &&
- calcassignments[i].calculatedop != thisop->op) {
+ calcassignments[i].calculatedop != thisop) {
i++;
}
if (calcassignments[i].calculatedop == ' ') {
- WINE_ERR("Unexpected operator %c\n", thisop->op);
+ WINE_ERR("Unexpected operator %c\n", thisop);
return WCMD_NOOPERATOR;
}
WCMD_pushoperator('=', WCMD_getprecedence('='), opstack);
@@ -3820,10 +3819,9 @@ static int WCMD_reduce(OPSTACK **opstack, VARSTACK **varstack) {
break;
}
- default: WINE_ERR("Unrecognized operator %c\n", thisop->op);
+ default: WINE_ERR("Unrecognized operator %c\n", thisop);
}
- heap_free(thisop);
return rc;
}
--
2.11.0
More information about the wine-patches
mailing list