diff --git a/stack.c b/stack.c index c425534..232a2b6 100644 --- a/stack.c +++ b/stack.c @@ -28,7 +28,12 @@ StackNode *pop(StackNode *stack) // Returns the data of the top element. void *top(StackNode *stack) { +if (stack == NULL) + return NULL; +StackNode *next = stack->next; +free(stack); +return next; } // Clears stack and releases all memory.