minor fixes and a malloc/free failure
fixing a bad free call