You must make sure to free the memory allocated when you don't need them anymore, that's the point.
If, by any chance, you lose the reference to a dynamically allocated address without freeing it then you'll have a memory leak, eh:
void pop() {
// get element from stack
// use it
// not call free
}
This will generate a leak if you don't store the address of the popped item anywhere.
If you want to reuse the allocated items then you are free to do it, and in this case you shouldn't free them, eg:
void push() {
struct Node *ptr = pop_unused_node();
if (!ptr) // if no unused node is found then we need a new one
ptr = malloc(sizeof(struct Node));
*ptr = data;
push(ptr);
}
void pop() {
struct Node *ptr = pop();
// use data
push_unused_node(ptr);
}
void clearup() {
for each node in unused list
free(node);
for each node in stack
free(node);
}