Fix dangling pointer in dup_args_

Also move dup_args_ into src/Misc.c and add a unit test.
Move command logging to time of actually execution