这个
res->next = malloc(sizeof(StackNode));
可能应该只是
res->next = NULL;
如果之后分配,则完全删除。
同样 pop 不应该 free 这个 next 项目,或者你将有双倍免费。
pop
free
next