Well, Though the above code is not freeing up the memory allocated to ‘ptr’ but still this would not cause a memory leak as after the processing is done the program exits. Well this is always true, so I guess that means there's no such thing as memory leaks in C. Checkmate garbage collectors.
To illustrate the difference, I wrote two quick programs.
This one has memory that the OS can recover:
#include
int main(void) {
char *a = malloc(10);
return 0;
}
This one has memory that the OS cannot recover: #include
int main(void) {
char *a = malloc(10);
a = malloc(10);
return 0;
}