Fixed various memory leaks, allocation size issues and API misuse
authorArmin Novak <anovak@thinstuff.com>
Fri, 30 Aug 2013 12:19:50 +0000 (14:19 +0200)
committerArmin Novak <anovak@thinstuff.com>
Thu, 5 Sep 2013 10:14:34 +0000 (12:14 +0200)
warnings shown by clang as well as some compiler warnings.

27 files changed:
channels/rdpsnd/client/rdpsnd_main.c
channels/smartcard/client/smartcard_operations.c
channels/urbdrc/client/urbdrc_main.c
client/Sample/freerdp.c
client/X11/generate_argument_docbook.c
client/X11/xf_client.c
libfreerdp/codec/mppc_dec.c
libfreerdp/codec/rfx.c
libfreerdp/core/gateway/http.c
libfreerdp/core/gateway/tsg.c
libfreerdp/core/window.c
libfreerdp/crypto/crypto.c
libfreerdp/crypto/tls.c
libfreerdp/rail/icon.c
server/Sample/sfreerdp.c
server/X11/xf_interface.c
winpr/include/winpr/collections.h
winpr/include/winpr/platform.h
winpr/libwinpr/handle/handle.c
winpr/libwinpr/input/scancode.c
winpr/libwinpr/input/virtualkey.c
winpr/libwinpr/path/shell.c
winpr/libwinpr/pipe/test/TestPipeCreateNamedPipe.c
winpr/libwinpr/pipe/test/TestPipeCreateNamedPipeOverlapped.c
winpr/libwinpr/sspi/sspi.c
winpr/libwinpr/sysinfo/sysinfo.c
winpr/libwinpr/utils/collections/ListDictionary.c

index f8d6122..5047ed7 100644 (file)
@@ -146,8 +146,10 @@ void rdpsnd_select_supported_audio_formats(rdpsndPlugin* rdpsnd)
        rdpsnd->NumberOfClientFormats = 0;
        rdpsnd->ClientFormats = NULL;
 
-       rdpsnd->ClientFormats = (AUDIO_FORMAT*) malloc(sizeof(AUDIO_FORMAT) * rdpsnd->NumberOfServerFormats);
+       if (!rdpsnd->NumberOfServerFormats)
+               return;
 
+       rdpsnd->ClientFormats = (AUDIO_FORMAT*) malloc(sizeof(AUDIO_FORMAT) * rdpsnd->NumberOfServerFormats);
        for (index = 0; index < (int) rdpsnd->NumberOfServerFormats; index++)
        {
                serverFormat = &rdpsnd->ServerFormats[index];
index e36b6d8..c72f38d 100644 (file)
@@ -1234,7 +1234,10 @@ static UINT32 handle_LocateCardsByATR(IRP* irp, BOOL wide)
        ZeroMemory(readerStates, readerCount * sizeof(SCARD_READERSTATE));
 
        if (!readerStates)
+       {
+               free(pAtrMasks);
                return smartcard_output_return(irp, SCARD_E_NO_MEMORY);
+       }
 
        for (i = 0; i < readerCount; i++)
        {
@@ -1284,6 +1287,8 @@ static UINT32 handle_LocateCardsByATR(IRP* irp, BOOL wide)
                DEBUG_SCARD("Failure: %s (0x%08x)",
                        pcsc_stringify_error(status), (unsigned) status);
 
+               free(readerStates);
+               free(pAtrMasks);
                return smartcard_output_return(irp, status);
        }
 
@@ -1313,7 +1318,7 @@ static UINT32 handle_LocateCardsByATR(IRP* irp, BOOL wide)
        Stream_Write_UINT32(irp->output, 0x00084dd8);
        Stream_Write_UINT32(irp->output, readerCount);
 
-       for (i = 0, rsCur = readerStates; i < readerCount; i++, rsCur++)
+       for (i = 0, cur = readerStates; i < readerCount; i++, cur++)
        {
                Stream_Write_UINT32(irp->output, cur->dwCurrentState);
                Stream_Write_UINT32(irp->output, cur->dwEventState);
@@ -1328,6 +1333,7 @@ static UINT32 handle_LocateCardsByATR(IRP* irp, BOOL wide)
        smartcard_output_alignment(irp, 8);
 
        free(readerStates);
+       free(pAtrMasks);
 
        return status;
 }
index d7628f3..e010bba 100644 (file)
@@ -18,6 +18,7 @@
  * limitations under the License.
  */
 
+#include <assert.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -287,6 +288,9 @@ static int urdbrc_send_virtual_channel_add(IWTSVirtualChannel* channel, UINT32 M
 
        LLOGLN(10, ("urdbrc_send_virtual_channel_add"));
 
+       assert(NULL != channel);
+       assert(NULL != channel->Write);
+
        InterfaceId = ((STREAM_ID_PROXY<<30) | CLIENT_DEVICE_SINK);
 
        out_size = 12;
@@ -830,7 +834,10 @@ static int urbdrc_on_data_received(IWTSVirtualChannelCallback* pChannelCallback,
                        transfer_data = (TRANSFER_DATA*) malloc(sizeof(TRANSFER_DATA));
 
                        if (transfer_data == NULL)
+                       {
                                fprintf(stderr, "transfer_data is NULL!!");
+                               return 0;
+                       }
 
                        transfer_data->callback = callback;
                        transfer_data->urbdrc = urbdrc;
index 9892811..87e4eb1 100644 (file)
@@ -206,9 +206,6 @@ int tfreerdp_run(freerdp* instance)
        fd_set wfds_set;
        rdpChannels* channels;
 
-       ZeroMemory(rfds, sizeof(rfds));
-       ZeroMemory(wfds, sizeof(wfds));
-
        channels = instance->context->channels;
 
        freerdp_connect(instance);
@@ -218,6 +215,8 @@ int tfreerdp_run(freerdp* instance)
                rcount = 0;
                wcount = 0;
 
+               ZeroMemory(rfds, sizeof(rfds));
+               ZeroMemory(wfds, sizeof(wfds));
                if (freerdp_get_fds(instance, rfds, &rcount, wfds, &wcount) != TRUE)
                {
                        printf("Failed to get FreeRDP file descriptor\n");
index 0c1da21..09ac6a3 100644 (file)
@@ -11,7 +11,7 @@
 
 LPSTR tmp = NULL;
 
-LPCSTR tr_esc_str(LPCSTR arg)
+LPSTR tr_esc_str(LPSTR arg)
 {
        size_t cs = 0, x, ds;
        size_t s;
@@ -26,7 +26,8 @@ LPCSTR tr_esc_str(LPCSTR arg)
                s--;
 
        /* Prepare a initial buffer with the size of the result string. */
-       tmp = malloc(s * sizeof(LPCSTR));
+       if (s)
+               tmp = (LPSTR)malloc(s * sizeof(CHAR));
        if( NULL == tmp )
        {
                fprintf(stderr, "Could not allocate string buffer.");
@@ -41,7 +42,7 @@ LPCSTR tr_esc_str(LPCSTR arg)
                {
                        case '<':
                                ds += 3;
-                               tmp = realloc(tmp, ds * sizeof(LPCSTR));
+                               tmp = (LPSTR)realloc(tmp, ds * sizeof(CHAR));
                                if( NULL == tmp )
                                {
                                        fprintf(stderr, "Could not reallocate string buffer.");
@@ -54,7 +55,7 @@ LPCSTR tr_esc_str(LPCSTR arg)
                                break;
                        case '>':
                                ds += 3;
-                               tmp = realloc(tmp, ds * sizeof(LPCSTR));
+                               tmp = (LPSTR)realloc(tmp, ds * sizeof(CHAR));
                                if( NULL == tmp )
                                {
                                        fprintf(stderr, "Could not reallocate string buffer.");
@@ -67,7 +68,7 @@ LPCSTR tr_esc_str(LPCSTR arg)
                                break;
                        case '\'':
                                ds += 5;
-                               tmp = realloc(tmp, ds * sizeof(LPCSTR));
+                               tmp = (LPSTR)realloc(tmp, ds * sizeof(CHAR));
                                if( NULL == tmp )
                                {
                                        fprintf(stderr, "Could not reallocate string buffer.");
@@ -82,7 +83,7 @@ LPCSTR tr_esc_str(LPCSTR arg)
                                break;
                        case '"':
                                ds += 5;
-                               tmp = realloc(tmp, ds * sizeof(LPCSTR));
+                               tmp = (LPSTR)realloc(tmp, ds * sizeof(CHAR));
                                if( NULL == tmp )
                                {
                                        fprintf(stderr, "Could not reallocate string buffer.");
@@ -97,7 +98,7 @@ LPCSTR tr_esc_str(LPCSTR arg)
                                break;
                        case '&':
                                ds += 4;
-                               tmp = realloc(tmp, ds * sizeof(LPCSTR));
+                               tmp = (LPSTR)realloc(tmp, ds * sizeof(CHAR));
                                if( NULL == tmp )
                                {
                                        fprintf(stderr, "Could not reallocate string buffer.");
index 886c3a8..4e4bf10 100644 (file)
@@ -1650,7 +1650,7 @@ void xf_ParamChangeEventHandler(rdpContext* context, ParamChangeEventArgs* e)
        }
 }
 
-void xf_ScalingFactorChangeEventHandler(rdpContext* context, ScalingFactorChangeEventArgs* e)
+static void xf_ScalingFactorChangeEventHandler(rdpContext* context, ScalingFactorChangeEventArgs* e)
 {
        xfContext* xfc = (xfContext*) context;
 
@@ -1668,12 +1668,12 @@ void xf_ScalingFactorChangeEventHandler(rdpContext* context, ScalingFactorChange
        xf_transform_window(xfc);
 
        {
-               ResizeWindowEventArgs e;
+               ResizeWindowEventArgs ev;
 
-               EventArgsInit(&e, "xfreerdp");
-               e.width = (int) xfc->originalWidth * xfc->settings->ScalingFactor;
-               e.height = (int) xfc->originalHeight * xfc->settings->ScalingFactor;
-               PubSub_OnResizeWindow(((rdpContext*) xfc)->pubSub, xfc, &e);
+               EventArgsInit(&ev, "xfreerdp");
+               ev.width = (int) xfc->originalWidth * xfc->settings->ScalingFactor;
+               ev.height = (int) xfc->originalHeight * xfc->settings->ScalingFactor;
+               PubSub_OnResizeWindow(((rdpContext*) xfc)->pubSub, xfc, &ev);
        }
        xf_draw_screen_scaled(xfc, 0, 0, 0, 0, FALSE);
 
@@ -1683,19 +1683,19 @@ void xf_ScalingFactorChangeEventHandler(rdpContext* context, ScalingFactorChange
  * Client Interface
  */
 
-void xfreerdp_client_global_init()
+static void xfreerdp_client_global_init()
 {
        setlocale(LC_ALL, "");
        freerdp_handle_signals();
        freerdp_channels_global_init();
 }
 
-void xfreerdp_client_global_uninit()
+static void xfreerdp_client_global_uninit()
 {
        freerdp_channels_global_uninit();
 }
 
-int xfreerdp_client_start(rdpContext* context)
+static int xfreerdp_client_start(rdpContext* context)
 {
        xfContext* xfc = (xfContext*) context;
 
@@ -1712,7 +1712,7 @@ int xfreerdp_client_start(rdpContext* context)
        return 0;
 }
 
-int xfreerdp_client_stop(rdpContext* context)
+static int xfreerdp_client_stop(rdpContext* context)
 {
        xfContext* xfc = (xfContext*) context;
 
@@ -1735,7 +1735,7 @@ int xfreerdp_client_stop(rdpContext* context)
        return 0;
 }
 
-int xfreerdp_client_new(freerdp* instance, rdpContext* context)
+static int xfreerdp_client_new(freerdp* instance, rdpContext* context)
 {
        xfContext* xfc;
        rdpSettings* settings;
@@ -1791,7 +1791,7 @@ int xfreerdp_client_new(freerdp* instance, rdpContext* context)
        return 0;
 }
 
-void xfreerdp_client_free(freerdp* instance, rdpContext* context)
+static void xfreerdp_client_free(freerdp* instance, rdpContext* context)
 {
        xfContext* xfc = (xfContext*) context;
 
index ebd8fdc..b8bd8c4 100644 (file)
@@ -22,6 +22,7 @@
 #include "config.h"
 #endif
 
+#include <assert.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -179,8 +180,8 @@ int decompress_rdp_4(struct rdp_mppc_dec* dec, BYTE* cbuf, int len, int ctype, U
        BYTE*    src_ptr;        /* used while copying compressed data */
        BYTE*    cptr;           /* points to next byte in cbuf */
        BYTE     cur_byte;       /* last byte fetched from cbuf */
-       int       bits_left;      /* bits left in d34 for processing */
-       int       cur_bits_left;  /* bits left in cur_byte for processing */
+       unsigned int    bits_left;      /* bits left in d34 for processing */
+       unsigned int  cur_bits_left;  /* bits left in cur_byte for processing */
        int       tmp;
        UINT32    i32;
 
@@ -330,6 +331,7 @@ int decompress_rdp_4(struct rdp_mppc_dec* dec, BYTE* cbuf, int len, int ctype, U
                */
 
                /* how may bits do we need to get? */
+               assert(bits_left <= 32);
                tmp = 32 - bits_left;
 
                while (tmp)
@@ -338,7 +340,7 @@ int decompress_rdp_4(struct rdp_mppc_dec* dec, BYTE* cbuf, int len, int ctype, U
                        {
                                /* we have less bits than we need */
                                i32 = cur_byte >> (8 - cur_bits_left);
-                               d32 |= i32 << ((32 - bits_left) - cur_bits_left);
+                               d32 |= (i32 << ((32 - bits_left) - cur_bits_left)) & 0xFFFFFFFF;
                                bits_left += cur_bits_left;
                                tmp -= cur_bits_left;
                                if (cptr < cbuf + len)
@@ -527,6 +529,8 @@ int decompress_rdp_4(struct rdp_mppc_dec* dec, BYTE* cbuf, int len, int ctype, U
                */
 
                /* how may bits do we need to get? */
+               assert(bits_left <= 32);
+               assert(cur_bits_left <= bits_left);
                tmp = 32 - bits_left;
 
                while (tmp)
@@ -535,7 +539,7 @@ int decompress_rdp_4(struct rdp_mppc_dec* dec, BYTE* cbuf, int len, int ctype, U
                        {
                                /* we have less bits than we need */
                                i32 = cur_byte >> (8 - cur_bits_left);
-                               d32 |= i32 << ((32 - bits_left) - cur_bits_left);
+                               d32 |= (i32 << ((32 - bits_left) - cur_bits_left)) & 0xFFFFFFFF;
                                bits_left += cur_bits_left;
                                tmp -= cur_bits_left;
                                if (cptr < cbuf + len)
@@ -769,6 +773,8 @@ int decompress_rdp_5(struct rdp_mppc_dec* dec, BYTE* cbuf, int len, int ctype, U
                */
 
                /* how may bits do we need to get? */
+               assert(bits_left <= 32);
+               assert(cur_bits_left <= bits_left);
                tmp = 32 - bits_left;
 
                while (tmp)
@@ -777,7 +783,7 @@ int decompress_rdp_5(struct rdp_mppc_dec* dec, BYTE* cbuf, int len, int ctype, U
                        {
                                /* we have less bits than we need */
                                i32 = cur_byte >> (8 - cur_bits_left);
-                               d32 |= i32 << ((32 - bits_left) - cur_bits_left);
+                               d32 |= (32 << ((32 - bits_left) - cur_bits_left)) & 0xFFFFFFFF;
                                bits_left += cur_bits_left;
                                tmp -= cur_bits_left;
                                if (cptr < cbuf + len)
@@ -990,6 +996,8 @@ int decompress_rdp_5(struct rdp_mppc_dec* dec, BYTE* cbuf, int len, int ctype, U
                */
 
                /* how may bits do we need to get? */
+               assert(bits_left <= 32);
+               assert(cur_bits_left <= bits_left);
                tmp = 32 - bits_left;
 
                while (tmp)
@@ -998,7 +1006,7 @@ int decompress_rdp_5(struct rdp_mppc_dec* dec, BYTE* cbuf, int len, int ctype, U
                        {
                                /* we have less bits than we need */
                                i32 = cur_byte >> (8 - cur_bits_left);
-                               d32 |= i32 << ((32 - bits_left) - cur_bits_left);
+                               d32 |= (i32 << ((32 - bits_left) - cur_bits_left)) & 0xFFFFFFFF;
                                bits_left += cur_bits_left;
                                tmp -= cur_bits_left;
                                if (cptr < cbuf + len)
@@ -1322,6 +1330,8 @@ int decompress_rdp_6(struct rdp_mppc_dec* dec, BYTE* cbuf, int len, int ctype, U
                */
 
                /* how may bits do we need to get? */
+               assert(bits_left <= 32);
+               assert(cur_bits_left <= bits_left);
                tmp = 32 - bits_left;
 
                while (tmp)
@@ -1330,7 +1340,7 @@ int decompress_rdp_6(struct rdp_mppc_dec* dec, BYTE* cbuf, int len, int ctype, U
                        {
                                /* we have less bits than we need */
                                i32 = cur_byte >> (8 - cur_bits_left);
-                               d32 |= i32 << ((32 - bits_left) - cur_bits_left);
+                               d32 |= (i32 << ((32 - bits_left) - cur_bits_left)) & 0xFFFFFFFF;
                                bits_left += cur_bits_left;
                                tmp -= cur_bits_left;
                                if (cptr < cbuf + len)
index 00e6ade..6cc6e7f 100644 (file)
@@ -21,6 +21,7 @@
 #include "config.h"
 #endif
 
+#include <assert.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -756,6 +757,8 @@ static BOOL rfx_process_message_tileset(RFX_CONTEXT* context, RFX_MESSAGE* messa
 
                if (context->priv->UseThreads)
                {
+                       assert(params);
+
                        params[i].context = context;
                        params[i].tile = message->tiles[i];
 
@@ -1116,15 +1119,19 @@ RFX_MESSAGE* rfx_encode_message(RFX_CONTEXT* context, const RFX_RECT* rects,
        numTilesY = (height + 63) / 64;
 
        message->numTiles = numTilesX * numTilesY;
-       message->tiles = (RFX_TILE**) malloc(sizeof(RFX_TILE) * message->numTiles);
-       ZeroMemory(message->tiles, sizeof(RFX_TILE) * message->numTiles);
+       if (message->numTiles)
+       {
+               message->tiles = (RFX_TILE**) malloc(sizeof(RFX_TILE*) * message->numTiles);
+               ZeroMemory(message->tiles, sizeof(RFX_TILE*) * message->numTiles);
+       }
 
        DEBUG_RFX("x: %d y: %d width: %d height: %d scanline: %d BytesPerPixel: %d",
                        rect->x, rect->y, width, height, scanline, BytesPerPixel);
 
        if (context->priv->UseThreads)
        {
-               work_objects = (PTP_WORK*) malloc(sizeof(PTP_WORK) * message->numTiles);
+               if (message->numTiles)
+                       work_objects = (PTP_WORK*) malloc(sizeof(PTP_WORK) * message->numTiles);
                if (!work_objects)
                {
                        free(message);
@@ -1181,6 +1188,8 @@ RFX_MESSAGE* rfx_encode_message(RFX_CONTEXT* context, const RFX_RECT* rects,
 
                        if (context->priv->UseThreads)
                        {
+                               assert(params);
+
                                params[i].context = context;
                                params[i].tile = tile;
 
index aebaa73..d35a2c8 100644 (file)
@@ -503,7 +503,11 @@ HttpResponse* http_response_recv(rdpTls* tls)
                        }
 
                        http_response->count = count;
-                       http_response->lines = (char**) malloc(sizeof(char*) * http_response->count);
+                       if (count)
+                       {
+                               http_response->lines = (char**) malloc(sizeof(char*) * http_response->count);
+                               ZeroMemory(http_response->lines, sizeof(char*) * http_response->count);
+                       }
 
                        count = 0;
                        line = strtok((char*) buffer, "\r\n");
index 3a2008c..7ff6faa 100644 (file)
@@ -295,6 +295,9 @@ BOOL TsProxyCreateTunnelReadResponse(rdpTsg* tsg, RPC_PDU* pdu)
                {
                        fprintf(stderr, "Unexpected ComponentId: 0x%04X, Expected TS_GATEWAY_TRANSPORT\n",
                                        versionCaps->tsgHeader.ComponentId);
+                       free(packetCapsResponse);
+                       free(versionCaps);
+                       free(packet);
                        return FALSE;
                }
 
@@ -324,6 +327,7 @@ BOOL TsProxyCreateTunnelReadResponse(rdpTsg* tsg, RPC_PDU* pdu)
                        free(tsgCaps);
                        free(versionCaps);
                        free(packetCapsResponse);
+                       free(packet);
                        return FALSE;
                }
 
@@ -399,6 +403,8 @@ BOOL TsProxyCreateTunnelReadResponse(rdpTsg* tsg, RPC_PDU* pdu)
                {
                        fprintf(stderr, "Unexpected ComponentId: 0x%04X, Expected TS_GATEWAY_TRANSPORT\n",
                                versionCaps->tsgHeader.ComponentId);
+                       free(versionCaps);
+                       free(packetQuarEncResponse);
                        free(packet);
                        return FALSE;
                }
index 7422f5b..ea0a40f 100644 (file)
@@ -64,9 +64,17 @@ BOOL update_read_icon_info(wStream* s, ICON_INFO* icon_info)
 
        /* colorTable */
        if (icon_info->colorTable == NULL)
-               icon_info->colorTable = (BYTE*) malloc(icon_info->cbColorTable);
-       else
+       {
+               if (icon_info->cbColorTable)
+                       icon_info->colorTable = (BYTE*) malloc(icon_info->cbColorTable);
+       }
+       else if (icon_info->cbColorTable)
                icon_info->colorTable = (BYTE*) realloc(icon_info->colorTable, icon_info->cbColorTable);
+       else
+       {
+               free(icon_info->colorTable);
+               icon_info->colorTable = NULL;
+       }
        Stream_Read(s, icon_info->colorTable, icon_info->cbColorTable);
 
        /* bitsColor */
index f227e97..e84712b 100644 (file)
@@ -395,8 +395,8 @@ char* crypto_cert_subject_common_name(X509* xcert, int* length)
 char** crypto_cert_subject_alt_name(X509* xcert, int* count, int** lengths)
 {
        int index;
-       int length;
-       char** strings;
+       int length = 0;
+       char** strings = NULL;
        BYTE* string;
        int num_subject_alt_names;
        GENERAL_NAMES* subject_alt_names;
@@ -409,8 +409,11 @@ char** crypto_cert_subject_alt_name(X509* xcert, int* count, int** lengths)
                return NULL;
 
        num_subject_alt_names = sk_GENERAL_NAME_num(subject_alt_names);
-       strings = (char**) malloc(sizeof(char*) * num_subject_alt_names);
-       *lengths = (int*) malloc(sizeof(int*) * num_subject_alt_names);
+       if (num_subject_alt_names)
+       {
+               strings = (char**) malloc(sizeof(char*) * num_subject_alt_names);
+               *lengths = (int*) malloc(sizeof(int) * num_subject_alt_names);
+       }
 
        for (index = 0; index < num_subject_alt_names; ++index)
        {
index 401ef43..4eea0d3 100644 (file)
@@ -21,6 +21,8 @@
 #include "config.h"
 #endif
 
+#include <assert.h>
+
 #include <winpr/crt.h>
 #include <winpr/sspi.h>
 
@@ -717,6 +719,9 @@ void tls_print_certificate_name_mismatch_error(char* hostname, char* common_name
 {
        int index;
 
+       assert(NULL != hostname);
+       assert(NULL != common_name);
+       
        fprintf(stderr, "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n");
        fprintf(stderr, "@           WARNING: CERTIFICATE NAME MISMATCH!           @\n");
        fprintf(stderr, "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n");
@@ -726,11 +731,13 @@ void tls_print_certificate_name_mismatch_error(char* hostname, char* common_name
        fprintf(stderr, "\t%s\n", common_name ? common_name : "no CN found in certificate");
        if (alt_names_count > 1)
        {
+               assert(NULL != alt_names);
                fprintf(stderr, "Alternative names:\n");
                if (alt_names_count > 1)
                {
                        for (index = 0; index < alt_names_count; index++)
                        {
+                               assert(alt_names[index]);
                                fprintf(stderr, "\t %s\n", alt_names[index]);
                        }
                }
index 0dbaab0..04cef8e 100644 (file)
@@ -93,8 +93,11 @@ rdpIconCache* icon_cache_new(rdpRail* rail)
 
                for (i = 0; i < cache->numCaches; i++)
                {
-                       cache->caches[i].entries = malloc(cache->numCacheEntries * sizeof(rdpIconCache));
-                       ZeroMemory(cache->caches[i].entries, cache->numCacheEntries * sizeof(rdpIconCache));
+                       if (cache->numCacheEntries)
+                       {
+                               cache->caches[i].entries = malloc(cache->numCacheEntries * sizeof(rdpIcon));
+                               ZeroMemory(cache->caches[i].entries, cache->numCacheEntries * sizeof(rdpIcon));
+                       }
                }
        }
 
index e988a2e..b38fe46 100644 (file)
@@ -658,8 +658,6 @@ static void* test_peer_mainloop(void* arg)
        testPeerContext* context;
        freerdp_peer* client = (freerdp_peer*) arg;
 
-       memset(rfds, 0, sizeof(rfds));
-
        test_peer_init(client);
 
        /* Initialize the real server settings here */
@@ -694,6 +692,7 @@ static void* test_peer_mainloop(void* arg)
        {
                rcount = 0;
 
+               memset(rfds, 0, sizeof(rfds));
                if (client->GetFileDescriptor(client, rfds, &rcount) != TRUE)
                {
                        printf("Failed to get FreeRDP file descriptor\n");
@@ -779,12 +778,11 @@ static void test_server_mainloop(freerdp_listener* instance)
        void* rfds[32];
        fd_set rfds_set;
 
-       memset(rfds, 0, sizeof(rfds));
-
        while (1)
        {
                rcount = 0;
 
+               memset(rfds, 0, sizeof(rfds));
                if (instance->GetFileDescriptor(instance, rfds, &rcount) != TRUE)
                {
                        printf("Failed to get FreeRDP file descriptor\n");
index 1c93b5e..22e0386 100644 (file)
@@ -42,8 +42,6 @@ void* xf_server_thread(void* param)
        xfServer* server;
        freerdp_listener* listener;
 
-       ZeroMemory(rfds, sizeof(rfds));
-
        server = (xfServer*) param;
        listener = server->listener;
 
@@ -51,6 +49,7 @@ void* xf_server_thread(void* param)
        {
                rcount = 0;
 
+               ZeroMemory(rfds, sizeof(rfds));
                if (listener->GetFileDescriptor(listener, rfds, &rcount) != TRUE)
                {
                        fprintf(stderr, "Failed to get FreeRDP file descriptor\n");
index 2730ffe..f06d304 100644 (file)
@@ -475,9 +475,9 @@ typedef struct _wEventType wEventType;
 #define DEFINE_EVENT_END(_name) \
        } _name ## EventArgs; \
        DEFINE_EVENT_HANDLER(_name); \
-       DEFINE_EVENT_RAISE(_name); \
-       DEFINE_EVENT_SUBSCRIBE(_name); \
-       DEFINE_EVENT_UNSUBSCRIBE(_name);
+       DEFINE_EVENT_RAISE(_name) \
+       DEFINE_EVENT_SUBSCRIBE(_name) \
+       DEFINE_EVENT_UNSUBSCRIBE(_name)
 
 #define DEFINE_EVENT_ENTRY(_name) \
        { #_name, { sizeof( _name ## EventArgs) }, 0, { \
index f178b0c..ad2f618 100644 (file)
 
 /* Mac OS X (__MACOSX__) */
 
-#if (__APPLE__ && __MACH__)
+#if (defined(__APPLE__) && defined(__MACH__))
 #ifndef __MACOSX__
 #define __MACOSX__     1
 #endif
 
 /* iOS (__IOS__)*/
 
-#if (__APPLE__ && TARGET_OS_IPHONE)
+#if (defined(__APPLE__) && defined(TARGET_OS_IPHONE))
 #ifndef __IOS__
 #define __IOS__                1
 #endif
index 3031b03..31ac564 100644 (file)
@@ -48,8 +48,7 @@ BOOL CloseHandle(HANDLE hObject)
                WINPR_THREAD* thread;
 
                thread = (WINPR_THREAD*) Object;
-
-               free(Object);
+               free(thread);
 
                return TRUE;
        }
index e543fa8..fe08882 100644 (file)
@@ -33,7 +33,7 @@
  * Keyboard Type 4
  */
 
-DWORD KBD4T[128] =
+static DWORD KBD4T[128] =
 {
        KBD4_T00,
        KBD4_T01,
@@ -165,7 +165,7 @@ DWORD KBD4T[128] =
        KBD4_T7F
 };
 
-DWORD KBD4X[128] =
+static DWORD KBD4X[128] =
 {
        VK_NONE,
        VK_NONE,
@@ -301,7 +301,7 @@ DWORD KBD4X[128] =
  * Keyboard Type 7
  */
 
-DWORD KBD7T[128] =
+static DWORD KBD7T[128] =
 {
        KBD7_T00,
        KBD7_T01,
@@ -433,7 +433,7 @@ DWORD KBD7T[128] =
        KBD7_T7F
 };
 
-DWORD KBD7X[128] =
+static DWORD KBD7X[128] =
 {
        VK_NONE,
        VK_NONE,
index d5f8dd1..64f71f0 100644 (file)
@@ -437,7 +437,7 @@ char* GetVirtualKeyName(DWORD vkcode)
 
 DWORD GetVirtualKeyCodeFromName(const char* vkname)
 {
-       int i;
+       unsigned long i;
 
        for (i = 0; i < ARRAYSIZE(VIRTUAL_KEY_CODE_TABLE); i++)
        {
@@ -453,7 +453,7 @@ DWORD GetVirtualKeyCodeFromName(const char* vkname)
 
 DWORD GetVirtualKeyCodeFromXkbKeyName(const char* xkbname)
 {
-       int i;
+       unsigned long i;
 
        for (i = 0; i < ARRAYSIZE(XKB_KEYNAME_TABLE); i++)
        {
index ff1b2cf..573ee03 100644 (file)
@@ -290,7 +290,8 @@ char* GetCombinedPath(char* basePath, char* subPath)
        if (!path)
                return NULL;
 
-       CopyMemory(path, basePath, basePathLength);
+       if (basePath)
+               CopyMemory(path, basePath, basePathLength);
        path[basePathLength] = '\0';
 
        PathCchConvertStyleA(path, basePathLength, PATH_STYLE_NATIVE);
index 5204217..a6d4686 100644 (file)
@@ -55,6 +55,11 @@ static void* named_pipe_client_thread(void* arg)
        if (!fSuccess || (lpNumberOfBytesWritten == 0))
        {
                printf("Client NamedPipe WriteFile failure\n");
+       
+               free(lpReadBuffer);
+               free(lpWriteBuffer);
+
+               CloseHandle(hNamedPipe);
                return NULL;
        }
 
@@ -68,6 +73,10 @@ static void* named_pipe_client_thread(void* arg)
        if (!fSuccess || (lpNumberOfBytesRead == 0))
        {
                printf("Client NamedPipe ReadFile failure\n");
+               free(lpReadBuffer);
+               free(lpWriteBuffer);
+
+               CloseHandle(hNamedPipe);
                return NULL;
        }
 
@@ -120,6 +129,8 @@ static void* named_pipe_server_thread(void* arg)
        if (!fConnected)
        {
                printf("ConnectNamedPipe failure\n");
+
+               CloseHandle(hNamedPipe);
                return NULL;
        }
 
@@ -136,6 +147,10 @@ static void* named_pipe_server_thread(void* arg)
        if (!fSuccess || (lpNumberOfBytesRead == 0))
        {
                printf("Server NamedPipe ReadFile failure\n");
+               free(lpReadBuffer);
+               free(lpWriteBuffer);
+
+               CloseHandle(hNamedPipe);
                return NULL;
        }
 
@@ -152,6 +167,10 @@ static void* named_pipe_server_thread(void* arg)
        if (!fSuccess || (lpNumberOfBytesWritten == 0))
        {
                printf("Server NamedPipe WriteFile failure\n");
+               free(lpReadBuffer);
+               free(lpWriteBuffer);
+
+               CloseHandle(hNamedPipe);
                return NULL;
        }
 
@@ -176,6 +195,9 @@ int TestPipeCreateNamedPipe(int argc, char* argv[])
        WaitForSingleObject(ClientThread, INFINITE);
        WaitForSingleObject(ServerThread, INFINITE);
 
+       CloseHandle(ClientThread);
+       CloseHandle(ServerThread);
+
        return 0;
 }
 
index f5524c3..fe71bff 100644 (file)
@@ -63,6 +63,11 @@ static void* named_pipe_client_thread(void* arg)
        if (!fSuccess)
        {
                printf("Client NamedPipe WriteFile failure: %d\n", GetLastError());
+               free(lpReadBuffer);
+               free(lpWriteBuffer);
+       
+               CloseHandle(hNamedPipe);
+               CloseHandle(hEvent);
                return NULL;
        }
 
@@ -85,6 +90,11 @@ static void* named_pipe_client_thread(void* arg)
        if (!fSuccess)
        {
                printf("Client NamedPipe ReadFile failure: %d\n", GetLastError());
+               free(lpReadBuffer);
+               free(lpWriteBuffer);
+
+               CloseHandle(hNamedPipe);
+               CloseHandle(hEvent);
                return NULL;
        }
 
@@ -160,6 +170,10 @@ static void* named_pipe_server_thread(void* arg)
        if (!fConnected)
        {
                printf("ConnectNamedPipe failure: %d\n", GetLastError());
+
+               CloseHandle(hNamedPipe);
+               CloseHandle(hEvent);
+
                return NULL;
        }
 
@@ -178,6 +192,12 @@ static void* named_pipe_server_thread(void* arg)
        if (!fSuccess)
        {
                printf("Server NamedPipe ReadFile failure: %d\n", GetLastError());
+               free(lpReadBuffer);
+               free(lpWriteBuffer);
+
+               CloseHandle(hNamedPipe);
+               CloseHandle(hEvent);
+
                return NULL;
        }
 
@@ -203,6 +223,13 @@ static void* named_pipe_server_thread(void* arg)
        if (!fSuccess)
        {
                printf("Server NamedPipe WriteFile failure: %d\n", GetLastError());
+       
+               free(lpReadBuffer);
+               free(lpWriteBuffer);
+
+               CloseHandle(hNamedPipe);
+               CloseHandle(hEvent);
+
                return NULL;
        }
 
index 96c9599..c0562bd 100644 (file)
@@ -140,10 +140,13 @@ void sspi_ContextBufferAllocTableNew()
 void sspi_ContextBufferAllocTableGrow()
 {
        size_t size;
+       ContextBufferAllocTable.entries = NULL;
        ContextBufferAllocTable.cEntries = 0;
        ContextBufferAllocTable.cMaxEntries *= 2;
 
        size = sizeof(CONTEXT_BUFFER_ALLOC_ENTRY) * ContextBufferAllocTable.cMaxEntries;
+       if (!size)
+               return;
 
        ContextBufferAllocTable.entries = realloc(ContextBufferAllocTable.entries, size);
        ZeroMemory((void*) &ContextBufferAllocTable.entries[ContextBufferAllocTable.cMaxEntries / 2], size / 2);
index 356b0a9..9091c5e 100644 (file)
@@ -90,7 +90,7 @@ defined(__OpenBSD__) || defined(__DragonFly__)
 #include <sys/sysctl.h>
 #endif
 
-DWORD GetProcessorArchitecture()
+static DWORD GetProcessorArchitecture()
 {
        DWORD cpuArch = PROCESSOR_ARCHITECTURE_UNKNOWN;
 
@@ -113,7 +113,7 @@ DWORD GetProcessorArchitecture()
        return cpuArch;
 }
 
-DWORD GetNumberOfProcessors()
+static DWORD GetNumberOfProcessors()
 {
        DWORD numCPUs = 1;
 
index cb7ba42..aa817a5 100644 (file)
@@ -248,7 +248,7 @@ void ListDictionary_Remove(wListDictionary* listDictionary, void* key)
 void* ListDictionary_GetItemValue(wListDictionary* listDictionary, void* key)
 {
        void* value = NULL;
-       wListDictionaryItem* item;
+       wListDictionaryItem* item = NULL;
 
        if (listDictionary->synchronized)
                EnterCriticalSection(&listDictionary->lock);