Fix memory leak

This commit is contained in:
Inex Code 2020-03-07 14:24:02 +03:00
parent b7c0451cd2
commit eca8a60141

View file

@ -120,6 +120,10 @@ int parse(char *s, STACK* stack) {
int main(int argc, char **argv) { int main(int argc, char **argv) {
STACK* operands = init_stack(argc); STACK* operands = init_stack(argc);
if (operands == NULL) {
fprintf(stderr, "Error creating operand stack.\n");
return(2);
}
int error; int error;
while(*++argv) { while(*++argv) {
error = parse(*argv, operands); error = parse(*argv, operands);
@ -131,6 +135,7 @@ int main(int argc, char **argv) {
int i; int i;
printf("Stack status:\n"); printf("Stack status:\n");
for (i = (operands -> cnt); i > 0; i--) printf("%f\n", pop(operands)); for (i = (operands -> cnt); i > 0; i--) printf("%f\n", pop(operands));
destroy_stack(operands);
return 0; return 0;
} }