]> git.unchartedbackwaters.co.uk Git - francis/winuae.git/commitdiff
Fix calculator memory double free
authorToni Wilen <twilen@winuae.net>
Sun, 14 May 2023 17:29:23 +0000 (20:29 +0300)
committerToni Wilen <twilen@winuae.net>
Sun, 14 May 2023 17:29:23 +0000 (20:29 +0300)
calc.cpp

index eaa10fd958ee42059c750b360968f4dc2a938dab..d1812203a72e6813ebc3b9a280ebb7ac890e37dc 100644 (file)
--- a/calc.cpp
+++ b/calc.cpp
@@ -548,7 +548,8 @@ static bool execution_order(const TCHAR *input, double *outval, TCHAR *outstring
                                                stack[sl].val = val;
                         xfree(stack[sl].vals);
                         stack[sl].vals = my_strdup(vals);
-                                               stack[sl].s = NULL;
+                        xfree(stack[sl].s);
+                        stack[sl].s = NULL;
             ++sl;
         }
         ++strpos;
@@ -569,8 +570,12 @@ static bool execution_order(const TCHAR *input, double *outval, TCHAR *outstring
                 }
                                ok = true;
                }
-               for (i = 0; i < STACK_SIZE; i++)
-                       xfree (stack[i].s);
+               for (i = 0; i < STACK_SIZE; i++) {
+            xfree(stack[i].s);
+            stack[i].s = NULL;
+            xfree(stack[i].vals);
+            stack[i].vals = NULL;
+        }
  
                // If there are more values in the stack
         // (Error) The user input has too many values.