resolve memory leak due to duplicating strings

resolve memory leak due to duplicating strings and not freeing them.

Also replaced dupstr() with strdup()

Actually using a static buffer in the calling function would probably be even better