cmd_set_window: fix memleaks

Caught by clang static analyzer.

While at it, fix some trailing spaces.
cmd_type: fix memleaks, fix crash on missing text

Caught by clang static analyzer: Memory leak.

Fix crash similar to `xdotool exec`:

    valgrind xdotool type --terminator x x
script_main: fix integer overflow, memleaks

Caught by clang static analyzer: Memory leak.

While fixing the memory leaks, I also found an integer overflow. The
following tries to access argv[-2], leading to a segfault:

    echo '$4294967294' | xdotool -

Other changes: replace calloc + strcpy by strdup, remove trailing
whitespace.