namec(..) advances the name-pointer, so free fails if it has been advanced enough. (dont) try ls '#I10'. free(name) replaced with free(aname)