Hewlett Packard Interview Question
ConsultantsCountry: India
Interview Type: In-Person
Char *ptr1= malloc(sizeof(5));
Char *ptr2= malloc(sizeof(6));
ptr1=ptr2;
free (ptr1); /* now it frees the ptr2 allocation */
here the 5 allocated is memory leak which can be freed as we dont have the pointer of that memory location.
When Dynamically allocated memory is not freed after its use, it leads to memory leak.
- Avi June 19, 2012It is a very sensitive issue in embedded programming