core/gateway/rpc: Fix leak found by covscan
authorOndrej Holy <oholy@redhat.com>
Fri, 17 Aug 2018 14:00:19 +0000 (16:00 +0200)
committerOndrej Holy <oholy@redhat.com>
Wed, 22 Aug 2018 12:34:02 +0000 (14:34 +0200)
0 is valid return value from socket().

leaked_storage: Variable "auth_3_pdu" going out of scope leaks the storage it points to.
leaked_storage: Variable "response" going out of scope leaks the storage it points to.
leaked_handle: Handle variable "sockfd" going out of scope leaks the handle.

libfreerdp/core/gateway/rpc.c
libfreerdp/core/gateway/rpc_bind.c
libfreerdp/core/gateway/rpc_client.c

index d01e309..3897817 100644 (file)
@@ -740,7 +740,7 @@ static int rpc_channel_tls_connect(RpcChannel* channel, int timeout)
        sockfd = freerdp_tcp_connect(context, settings, peerHostname,
                                     peerPort, timeout);
 
-       if (sockfd < 1)
+       if (sockfd < 0)
                return -1;
 
        socketBio = BIO_new(BIO_s_simple_socket());
index 54fd322..81516d9 100644 (file)
@@ -349,7 +349,10 @@ int rpc_send_rpc_auth_3_pdu(rdpRpc* rpc)
        buffer = (BYTE*) malloc(auth_3_pdu->frag_length);
 
        if (!buffer)
+       {
+               free(auth_3_pdu);
                return -1;
+       }
 
        CopyMemory(buffer, auth_3_pdu, 20);
        offset = 20;
index 9bd1bcf..0bee974 100644 (file)
@@ -476,6 +476,7 @@ static int rpc_client_default_out_channel_recv(rdpRpc* rpc)
                        /* Receive OUT Channel Response */
                        if (rpc_ncacn_http_recv_out_channel_response(rpc, outChannel, response) < 0)
                        {
+                               http_response_free(response);
                                WLog_ERR(TAG, "rpc_ncacn_http_recv_out_channel_response failure");
                                return -1;
                        }
@@ -484,6 +485,7 @@ static int rpc_client_default_out_channel_recv(rdpRpc* rpc)
 
                        if (rpc_ncacn_http_send_out_channel_request(rpc, outChannel, FALSE) < 0)
                        {
+                               http_response_free(response);
                                WLog_ERR(TAG, "rpc_ncacn_http_send_out_channel_request failure");
                                return -1;
                        }
@@ -496,6 +498,7 @@ static int rpc_client_default_out_channel_recv(rdpRpc* rpc)
 
                        if (rts_send_CONN_A1_pdu(rpc) < 0)
                        {
+                               http_response_free(response);
                                WLog_ERR(TAG, "rpc_send_CONN_A1_pdu error!");
                                return -1;
                        }