netutils/websocket: fixes minor issues in websocket
authorJunyeon LEE <junyeon2.lee@samsung.com>
Thu, 20 Apr 2017 08:32:37 +0000 (17:32 +0900)
committerHeesub Shin <heesub.shin@samsung.com>
Sat, 6 May 2017 10:51:22 +0000 (19:51 +0900)
This commit fixes minor issues in websocket library.
 . clearify socket close routine
 . clearify the context compare

Change-Id: I9a6ccf5504f4615bdb5d737c96eaa46c73c1a58a
Signed-off-by: Junyeon LEE <junyeon2.lee@samsung.com>
apps/netutils/websocket/websocket.c

index 23ec1f0..f555a9d 100644 (file)
@@ -338,7 +338,11 @@ EXIT_WEBSOCKET_HANDSHAKE_ERROR:
 
 void websocket_socket_free(websocket_t *ctx)
 {
-       if (ctx != NULL || ctx->fd >= 0) {
+       if (ctx == NULL) {
+               return;
+       }
+
+       if (ctx->fd >= 0) {
                close(ctx->fd);
                ctx->fd = -1;
        }
@@ -773,7 +777,6 @@ websocket_return_t websocket_client_open(websocket_t *client, char *host, char *
 
        if (websocket_client_handshake(client, host, port, path) != WEBSOCKET_SUCCESS) {
                WEBSOCKET_DEBUG("fail to http handshake\n");
-               close(fd);
                r = WEBSOCKET_HANDSHAKE_ERROR;
                goto EXIT_CLIENT_OPEN;
        }
@@ -781,7 +784,6 @@ websocket_return_t websocket_client_open(websocket_t *client, char *host, char *
        socket_data = malloc(sizeof(struct websocket_info_t));
        if (socket_data == NULL) {
                WEBSOCKET_DEBUG("fail to allocate memory\n");
-               close(fd);
                r = WEBSOCKET_ALLOCATION_ERROR;
                goto EXIT_CLIENT_OPEN;
        }
@@ -791,7 +793,6 @@ websocket_return_t websocket_client_open(websocket_t *client, char *host, char *
        if (wslay_event_context_client_init(&client->ctx, client->cb, socket_data) != WEBSOCKET_SUCCESS) {
                WEBSOCKET_DEBUG("fail to init websocket client context\n");
                free(socket_data);
-               close(fd);
                r = WEBSOCKET_INIT_ERROR;
                goto EXIT_CLIENT_OPEN;
        }