You can always make use of the atexit() system call to add cleaning functions, in case the process is terminated by xmemory and not by your own code.