+ 3

Please, Explain... Why there is a memory leak in the following code?

int *ptr = (int*)malloc(sizeof(int)); ptr = NULL; free(ptr);

13th May 2019, 4:24 AM
Sp Maurya
Sp Maurya - avatar
4 odpowiedzi
+ 4
Without the second line, there is no memory leak.
13th May 2019, 5:19 AM
Sonic
Sonic - avatar
+ 1
it means we can not free a null pointer ?
13th May 2019, 4:27 AM
Sp Maurya
Sp Maurya - avatar
+ 1
ok now i understand it, after you edited the answer... thanks for your help...
13th May 2019, 4:41 AM
Sp Maurya
Sp Maurya - avatar
+ 1
😀😁😘😘
13th May 2019, 4:54 AM
Sp Maurya
Sp Maurya - avatar