reorder calls to myfree to fit the order in struct and add missing free for hostname