Consider this pointless program:
/* main.c */
#include <stdlib.h>
#include <unistd.h>
int main(int argc, char **argv) {
int i;
for (i = 0; i < 1024; i++) {
int pid = fork();
int status;
if (pid) {
wait(&status);
}
else {
char *ptr = (char *)malloc(1024*sizeof(char));
char *args[2] = {"Hello, world!", NULL};
execve("/bin/echo", args, NULL);
}
}
}
Would not freeing ptr
constitute a memory leak for either main.c or the other program, or is it going to be freed anyway when execve is called?