gateway: Fix bogus DISCONNECTED->CONNECTED state change

If there's an ongoing connect to gw->sco while we disconnect the gateway
through gateway_close(), we are not really shutting down gw->sco because it
will be NULL until sco_connect_cb() is called.

If we disconnected this way we will receive a timeout much later on
gw->sco and make the bogus transition DISCONNECTED->CONNECTED because we
try to suspend the stream instead of closing it.

In the callback we could check the state before suspending the stream,
but there's no reason to wait the timeout and not shutting down the
channel when we disconnected. This also fix a potential leak of io,
since we were unconditionally incrementing its ref.

Now we set gw->sco as soon as we try to connect to it, but change the
check for "is the sco usable?" by checking gw->sco_id, that is only set
on the callback.
gateway: Fix leaking agent on exit

==1422== 69 (32 direct, 37 indirect) bytes in 1 blocks are definitely lost in loss record 208 of 281
==1422==    at 0x4C29E84: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==1422==    by 0x4E80938: g_malloc0 (in /usr/lib/libglib-2.0.so.0.3600.2)
==1422==    by 0x1292F4: register_agent (gateway.c:761)
==1422==    by 0x124305: process_message.isra.0 (object.c:197)
==1422==    by 0x514E545: ??? (in /usr/lib/libdbus-1.so.3.7.3)
==1422==    by 0x51410F0: dbus_connection_dispatch (in /usr/lib/libdbus-1.so.3.7.3)
==1422==    by 0x122AF7: message_dispatch (mainloop.c:76)
==1422==    by 0x4E7B9A2: ??? (in /usr/lib/libglib-2.0.so.0.3600.2)
==1422==    by 0x4E7AE45: g_main_context_dispatch (in /usr/lib/libglib-2.0.so.0.3600.2)
==1422==    by 0x4E7B197: ??? (in /usr/lib/libglib-2.0.so.0.3600.2)
==1422==    by 0x4E7B599: g_main_loop_run (in /usr/lib/libglib-2.0.so.0.3600.2)
==1422==    by 0x122255: main (main.c:542)