Check S_ISDIR in is_executable().

Travis says os_can_exe returns true when given a directory. Don't.

Misc change: free(buf) unconditionally.

This commit will likely be squashed later.