in reply to memory leak Issue

It has nothing to do with the memory-leak issue, but why are you using subroutine prototypes? They are not --as many erroneously think-- a way to check the validity of the argument list (see: When to use Prototypes? and Re: Are prototypes evil?).

CountZero

A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James