That valgrind report does not help. If your program exits normally, then all memory will be reclaimed by the operating system. It might be that Asterisk itself has a problem when launching external processes, or it could launch your script not as an external program but in-process like mod_perl does. I don't know Asterisk, but if your program writes to its own logfile, you might be able to find out whether your program really finishes by adding some strategic BEGIN{} and END{} blocks, or by reading the Asterisk documentation about how it runs AGI scripts (if your script is launched as AGI).