What happens to malloc'ed memory after exec() changes the program image? <p>I know that when I call one of the <code>exec()</code> system calls in Linux that it will replace the currently running process with a new image. So when I fork a new process and run <code>exec()</code>, the child will be replaced with the new process.</p> <p>What happens to any memory I've allocated from the heap? Say I want to parse an arbitrary number of commands and send it into <code>exec()</code>. To hold this arbitrary number, I'll likely have to allocate memory at some point since I don't think I can do it correctly with static sized arrays, so I'll likely use <code>malloc()</code> or something equivalent.</p> <p>I need to keep this memory allocated until after I've called <code>exec()</code>, but <code>exec()</code> never returns.</p> <p>Does the memory get reclaimed by the operating system?</p>