xdo: fix memleaks, fix undefined behavior

Caught by clang static analyzer: Result of operation is garbage or
undefined

- xdo_get_window_name: fix undefined behavior.
- xdo_get_desktop_viewport: fix undefined behavior, fix memleak on error
  path.
- xdo_wait_for_mouse_move_{from,to}: fix undefined behavior. Now it does
  not keep trying getting the cursor position on failure (i.e.
  BadWindow).
- xdo_get_{pid,active}_window, xdo_[gs]et_desktop_for_window,
  xdo_get_current_desktop, xdo_get_number_of_desktops: fix undefined
  behavior. Also correct resource deallocation, use XFree instead of
  free.
- xdo_get_mouse_location2: reword return error condition (no functional
  changes).
xdo: fix undefined behavior, fix memleak

Caught by clang static analyzer: Result of operation is garbage or
undefined.

Now it also returns early when XQueryTree fails (with BadWindow error).
xdo: fix undef behavior in xdo_wait_for_window_size

Caught by clang static analyzer: Result of operation is garbage or
undefined.

This prevents the function from trying getting the window size on
something that is gone (BadWindow). The caller (cmd_windowsize) does not
care about the status code, but that probably does not matter as it is
used for synchronization and technically "the window is not of the old
size" anymore.