Fixed various memory leaks and compiler warnings.
authorArmin Novak <anovak@thinstuff.com>
Thu, 29 Aug 2013 09:07:19 +0000 (11:07 +0200)
committerArmin Novak <anovak@thinstuff.com>
Thu, 5 Sep 2013 10:14:33 +0000 (12:14 +0200)
channels/tsmf/client/alsa/tsmf_alsa.c
client/X11/xf_gdi.c
client/X11/xf_rail.c
include/freerdp/utils/debug.h
libfreerdp/core/freerdp.c
libfreerdp/core/listener.c
libfreerdp/crypto/tls.c
libfreerdp/utils/pcap.c
libfreerdp/utils/profiler.c
winpr/libwinpr/synch/sleep.c

index 74c78a7..a6b67d7 100644 (file)
@@ -74,11 +74,11 @@ static BOOL tsmf_alsa_open(ITSMFAudioDevice* audio, const char* device)
        if (!device)
        {
                if (!alsa->device[0])
-                       strcpy(alsa->device, "default");
+                       strncpy(alsa->device, "default", sizeof(alsa->device));
        }
        else
        {
-               strcpy(alsa->device, device);
+               strncpy(alsa->device, device, sizeof(alsa->device));
        }
 
        return tsmf_alsa_open_device(alsa);
index 158c617..eb295cd 100644 (file)
@@ -998,6 +998,8 @@ void xf_gdi_surface_bits(rdpContext* context, SURFACE_BITS_COMMAND* surface_bits
                                surface_bits_command->destLeft, surface_bits_command->destTop,
                                surface_bits_command->width, surface_bits_command->height);
                XFree(image);
+               free(xfc->bmp_codec_nsc);
+               xfc->bmp_codec_nsc = NULL;
 
                xf_gdi_surface_update_frame(xfc,
                        surface_bits_command->destLeft, surface_bits_command->destTop,
@@ -1026,6 +1028,8 @@ void xf_gdi_surface_bits(rdpContext* context, SURFACE_BITS_COMMAND* surface_bits
                                        surface_bits_command->destLeft, surface_bits_command->destTop,
                                        surface_bits_command->width, surface_bits_command->height);
                        XFree(image);
+                       free(xfc->bmp_codec_none);
+                       xfc->bmp_codec_none = NULL;
 
                        xf_gdi_surface_update_frame(xfc,
                                surface_bits_command->destLeft, surface_bits_command->destTop,
index 459d0f9..4e4f17f 100644 (file)
@@ -565,7 +565,7 @@ const char* movetype_names[] =
 
 void xf_process_rail_server_localmovesize_event(xfContext* xfc, rdpChannels* channels, wMessage* event)
 {
-       int x, y;
+       int x = 0, y = 0;
        rdpRail* rail;
        int direction = 0;
        Window child_window;
index eb6b613..a62ec19 100644 (file)
 #include <stdio.h>
 
 #define DEBUG_NULL(fmt, ...) do { } while (0)
-#define DEBUG_PRINT(_dbg_str, fmt, ...) fprintf(stderr, _dbg_str fmt "\n" , __FUNCTION__, __LINE__, ## __VA_ARGS__)
+#define DEBUG_PRINT(_dbg_str, fmt, ...) do { \
+               fprintf(stderr, _dbg_str, __FUNCTION__, __LINE__); \
+               fprintf(stderr, fmt, ## __VA_ARGS__); \
+               fprintf(stderr, "\n"); \
+       } while( 0 )
+
 #define DEBUG_CLASS(_dbg_class, fmt, ...) DEBUG_PRINT("DBG_" #_dbg_class " %s (%d): ", fmt, ## __VA_ARGS__)
 #define DEBUG_WARN(fmt, ...) DEBUG_PRINT("Warning %s (%d): ", fmt, ## __VA_ARGS__)
 
index d068bec..b0b8651 100644 (file)
@@ -164,7 +164,8 @@ BOOL freerdp_connect(freerdp* instance)
                                StreamPool_Return(rdp->transport->ReceivePool, s);
                        }
 
-
+                       pcap_close(update->pcap_rfx);
+                       update->pcap_rfx = NULL;
                        status = TRUE;
                        goto freerdp_connect_finally;
                }
@@ -306,6 +307,13 @@ BOOL freerdp_disconnect(freerdp* instance)
 
        IFCALL(instance->PostDisconnect, instance);
 
+       if (instance->update->pcap_rfx)
+       {
+               instance->update->dump_rfx = FALSE;
+               pcap_close(instance->update->pcap_rfx);
+               instance->update->pcap_rfx = NULL;
+       }
+
        return TRUE;
 }
 
index fb49bf3..b74c4ec 100644 (file)
@@ -306,6 +306,7 @@ static BOOL freerdp_listener_check_fds(freerdp_listener* instance)
                                continue;
 #endif
                        perror("accept");
+                       free(client);
                        return FALSE;
                }
 
index 3bcdc89..401ef43 100644 (file)
@@ -592,7 +592,7 @@ BOOL tls_verify_certificate(rdpTls* tls, CryptoCert cert, char* hostname)
                        }
                }
        
-               free(alt_names_length);
+               free(alt_names_lengths);
        }
 
        /* if the certificate is valid and the certificate name matches, verification succeeds */
index 52d912b..5e174a8 100644 (file)
@@ -218,4 +218,6 @@ void pcap_close(rdpPcap* pcap)
 
        if (pcap->fp != NULL)
                fclose(pcap->fp);
+
+       free(pcap);
 }
index 3d8fae6..794f3e7 100644 (file)
@@ -70,7 +70,8 @@ void profiler_print(PROFILER* profiler)
        double elapsed_sec = stopwatch_get_elapsed_time_in_seconds(profiler->stopwatch);
        double avg_sec = elapsed_sec / (double) profiler->stopwatch->count;
        
-       fprintf(stderr, "| %-30.30s| %10lu | %9f | %9f |\n", profiler->name, profiler->stopwatch->count, elapsed_sec, avg_sec);
+       fprintf(stderr, "| %-30.30s| %10lu | %9f | %9f |\n",
+                       profiler->name, profiler->stopwatch->count, elapsed_sec, avg_sec);
 }
 
 void profiler_print_footer()
index 096e243..6e83de7 100644 (file)
@@ -30,7 +30,9 @@
 #include <time.h>
 
 #ifdef HAVE_UNISTD_H
-#define _XOPEN_SOURCE 500
+       #ifndef _XOPEN_SOURCE
+               #define _XOPEN_SOURCE 500
+       #endif
 #include <unistd.h>
 #endif