fix possible memory leak, and reduce the amount of malloc's & free's when launching a new command, by using pointer offsets