Permalink
Browse files

Plugged another memory leak. The code should probably be more robust.

  • Loading branch information...
1 parent 9ad1ac4 commit 62356433a4e13b1872796288f9e9cd0d06b3ba8f @gnuvince committed Oct 5, 2010
Showing with 5 additions and 2 deletions.
  1. +5 −2 tp1_commun.c
View
@@ -475,27 +475,30 @@ int main(void) {
printf("EXPRESSION? ");
generation_error = GenerateAST(stack, &expression);
- result = ExprEvaluate(expression, &evaluate_error);
switch (generation_error) {
case ec_ok:
+ result = ExprEvaluate(expression, &evaluate_error);
if (evaluate_error == ec_div_zero)
printf("DIVISION PAR ZÉRO!\n");
else {
Report(expression);
printf(" Valeur: ");
printf("%d\n", result);
}
+ ExprFree(expression);
break;
case ec_invalid_symbol:
printf("SYMBOLE INVALIDE!\n");
EmptyInputBuffer();
+ ExprFree(expression);
break;
case ec_invalid_syntax:
printf("ERREUR DE SYNTAXE!\n");
EmptyInputBuffer();
+ ExprFree(expression);
break;
case ec_div_zero:
@@ -504,9 +507,9 @@ int main(void) {
break;
}
putchar('\n');
+
} while (generation_error != ec_eof);
- ExprFree(expression);
StackFree(stack);
return 0;
}

0 comments on commit 6235643

Please sign in to comment.