diff options
-rw-r--r-- | libcacard/vscclient.c | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/libcacard/vscclient.c b/libcacard/vscclient.c index ac23647..5180d29 100644 --- a/libcacard/vscclient.c +++ b/libcacard/vscclient.c @@ -618,18 +618,22 @@ connect_to_qemu( if (ret != 0) { /* Error */ fprintf(stderr, "getaddrinfo failed\n"); - return -1; + goto cleanup_socket; } if (connect(sock, server->ai_addr, server->ai_addrlen) < 0) { /* Error */ fprintf(stderr, "Could not connect\n"); - return -1; + goto cleanup_socket; } if (verbose) { printf("Connected (sizeof Header=%zd)!\n", sizeof(VSCMsgHeader)); } return sock; + +cleanup_socket: + closesocket(sock); + return -1; } int @@ -759,5 +763,6 @@ main( g_io_channel_unref(channel_socket); g_byte_array_unref(socket_to_send); + closesocket(sock); return 0; } |