resolve memory leak due to duplicating strings, and replaced dupstr() with strdup()