The module initializes itself (clears the global memory table, installs signal handling and exit routines) the first time a memory allocator is called.
Shutting down is done by attaching a cleanup function to the process end with atexit(). Cleaning up VM files is simple: loop from 1 to the highest file registration number, build up VM file names from this number and try to delete the corresponding file if it exists.
Another case to handle is sudden process interruption. There should be no remaining VM file around once the process is terminated. The easiest way to do that is to install a grabber for a number of interruption signals like SIGINT, SIGTERM, SIGBUS or SIGSEGV, and launch the cleanup procedure to remove all VM files before exiting. In the current implementation, the module makes use of the signal() system call to catch these signals, print out a message on stderr and call exit().
Attaching the cleanup procedure with atexit() also ensures that the filesystem used for VM file creation will be clean after a normal program termination, even in the case of memory leaks. The only case when a process will leave VM files behind is when it has been killed using the -KILL signal (which cannot be caught).