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;
More Related Contents:
- Access violation reading data from binary file into struct in C
- typedef struct vs struct definitions [duplicate]
- How to initialize a struct in accordance with C programming language standards
- How can I correctly assign a new string value?
- What REALLY happens when you don’t free after malloc before program termination?
- How does free know how much to free?
- Setting variable to NULL after free
- Does free(ptr) where ptr is NULL corrupt memory?
- Pointer to pointer of structs indexing out of bounds(?) when I try to index anything other than zero
- C – function inside struct
- Passing struct to function
- Why can’t we initialize members inside a structure?
- C typedef of pointer to structure
- Are C-structs with the same members types guaranteed to have the same layout in memory?
- Are “malloc(sizeof(struct a *))” and “malloc(sizeof(struct a))” the same?
- What does “request for member ‘*******’ in something not a structure or union” mean?
- memcpy vs assignment in C
- what is the difference between struct {0} and memset 0 [duplicate]
- Why declare a struct that only contains an array in C?
- How to include a dynamic array INSIDE a struct in C?
- Initializing a struct to 0
- C: Correctly freeing memory of a multi-dimensional array
- Why exactly should I not call free() on variables not allocated by malloc()?
- C Typedef – Incomplete Type
- How do you use offsetof() on a struct?
- How does C return a structure? [duplicate]
- How are we able to access the pointer after deallocating the memory?
- How to check if a pointer is freed already in C?
- Returning a struct pointer
- Why does static initialization of flexible array member work?