[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

execve - what happens to dynamically allocated memory?



The manpage for execve states:

       execve() does not return on success, and the  text,  data,
       bss,  and  stack of the calling process are overwritten by
       that of the program loaded.  The program invoked  inherits
       the  calling  process's PID, and any open file descriptors
       that are not set to close on exec...

I'm wondering what happens to dynamically allocated memory. For
example, if you have a code snippet such as:

child_argc = 5;
char** child_argv;
char buffer[MAX_STRING];
child_argv[0]="./a.out";
for( i = 1; i < child_argc; i++ )
{
  sprintf( buffer, "-%d", rand() );
  child_argv[i] = malloc( strlen(buffer) );
  strcpy( child_argv[i], buffer );
}
child_argv[i] = NULL;
execvp( child_argv[0], child_argv );


What happens to the dynamically allocated memory? FYI: I wrote the
above code off the top of my head, so it hasn't been check for actual
legal syntax.



Reply to: