From 7262ac588f70d2d4ca943ea5b386ad81076034ce Mon Sep 17 00:00:00 2001 From: Murilo Pereira Date: Tue, 31 May 2011 02:45:11 -0300 Subject: [PATCH] Fixed memory leak. --- lib/stack.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/stack.c b/lib/stack.c index 450e8b6..f3b5f99 100644 --- a/lib/stack.c +++ b/lib/stack.c @@ -52,9 +52,9 @@ void free_stack(struct stack *stack) { bool empty(struct stack *stack) { return(stack->card->value == NO_VALUE && - stack->card->suit == NO_SUIT && - stack->card->face == NO_FACE && - !stack->next); + stack->card->suit == NO_SUIT && + stack->card->face == NO_FACE && + !stack->next); } int length(struct stack *stack) { @@ -73,8 +73,9 @@ void push(struct stack **stack, struct card *card) { if (empty(*stack)) { (*stack)->card = card; } else { - struct stack *new_stack; - allocate_stack(&new_stack); + /* Allocating by hand because stack#allocate_stack would + * have allocated an unwanted card object. */ + struct stack *new_stack = malloc(sizeof(*new_stack)); new_stack->card = card; new_stack->next = (*stack); *stack = new_stack;