Fixed memory leak.

This commit is contained in:
Murilo Pereira 2011-05-31 02:45:11 -03:00
parent e5e94cc841
commit 7262ac588f

View File

@ -52,9 +52,9 @@ void free_stack(struct stack *stack) {
bool empty(struct stack *stack) { bool empty(struct stack *stack) {
return(stack->card->value == NO_VALUE && return(stack->card->value == NO_VALUE &&
stack->card->suit == NO_SUIT && stack->card->suit == NO_SUIT &&
stack->card->face == NO_FACE && stack->card->face == NO_FACE &&
!stack->next); !stack->next);
} }
int length(struct stack *stack) { int length(struct stack *stack) {
@ -73,8 +73,9 @@ void push(struct stack **stack, struct card *card) {
if (empty(*stack)) { if (empty(*stack)) {
(*stack)->card = card; (*stack)->card = card;
} else { } else {
struct stack *new_stack; /* Allocating by hand because stack#allocate_stack would
allocate_stack(&new_stack); * have allocated an unwanted card object. */
struct stack *new_stack = malloc(sizeof(*new_stack));
new_stack->card = card; new_stack->card = card;
new_stack->next = (*stack); new_stack->next = (*stack);
*stack = new_stack; *stack = new_stack;