Fixed a problem where a pointer was getting overwritten (basename returns a pointer to memory in the first argument).