free() not working correctly with struct

It is always a good habit to set the pointer to NULL after freeing it.
Since the memory you are accessing is still intact you are seeing right values for l->val.

Node *l=malloc(sizeof(Node));
l->key="foo";
l->val="bar";
free(l);
l = NULL;

Leave a Comment