I would change filename.gz into a stack array of size MAXPATH and remove the dynamic allocation completely.