xfreerdp: fix multiple memory leaks detected by valgrind
authorMarc-André Moreau <marcandre.moreau@gmail.com>
Mon, 27 Feb 2012 15:55:49 +0000 (10:55 -0500)
committerMarc-André Moreau <marcandre.moreau@gmail.com>
Mon, 27 Feb 2012 15:55:49 +0000 (10:55 -0500)
client/X11/xfreerdp.c
libfreerdp-crypto/tls.c
libfreerdp-locale/keyboard_xkb.c
libfreerdp-utils/file.c

index 3ee957d..8ee4f08 100644 (file)
@@ -1131,6 +1131,8 @@ int xfreerdp_run(freerdp* instance)
        gdi_free(instance);
        xf_free(xfi);
 
+       freerdp_context_free(instance);
+
        freerdp_free(instance);
 
        return ret;
index 9185d00..09df895 100644 (file)
@@ -282,13 +282,14 @@ boolean tls_verify_certificate(rdpTls* tls, CryptoCert cert, char* hostname)
 {
        int match;
        int index;
-       char* common_name;
-       int common_name_length;
-       char** alt_names;
-       int alt_names_count;
-       int* alt_names_lengths;
+       char* common_name = NULL;
+       int common_name_length = 0;
+       char** alt_names = NULL;
+       int alt_names_count = 0;
+       int* alt_names_lengths = NULL;
        boolean certificate_status;
        boolean hostname_match = false;
+       boolean verification_status = false;
        rdpCertificateData* certificate_data;
 
        /* ignore certificate verification if user explicitly required it (discouraged) */
@@ -336,7 +337,12 @@ boolean tls_verify_certificate(rdpTls* tls, CryptoCert cert, char* hostname)
 
        /* if the certificate is valid and the certificate name matches, verification succeeds */
        if (certificate_status && hostname_match)
-               return true; /* success! */
+       {
+               if (common_name)
+                       xfree(common_name);
+
+               verification_status = true; /* success! */
+       }
 
        /* if the certificate is valid but the certificate name does not match, warn user, do not accept */
        if (certificate_status && !hostname_match)
@@ -350,7 +356,6 @@ boolean tls_verify_certificate(rdpTls* tls, CryptoCert cert, char* hostname)
                char* subject;
                char* fingerprint;
                boolean accept_certificate = false;
-               boolean verification_status = false;
 
                issuer = crypto_cert_issuer(cert->px509);
                subject = crypto_cert_subject(cert->px509);
@@ -397,11 +402,27 @@ boolean tls_verify_certificate(rdpTls* tls, CryptoCert cert, char* hostname)
                xfree(issuer);
                xfree(subject);
                xfree(fingerprint);
+       }
+
+       if (common_name)
+               xfree(common_name);
 
-               return verification_status;
+       if (alt_names)
+       {
+               for (index = 0; index < alt_names_count; index++)
+                       xfree(alt_names[index]);
+
+               xfree(alt_names);
+       }
+
+       if (certificate_data)
+       {
+               xfree(certificate_data->fingerprint);
+               xfree(certificate_data->hostname);
+               xfree(certificate_data);
        }
 
-       return false;
+       return verification_status;
 }
 
 void tls_print_certificate_error(char* hostname, char* fingerprint)
index 5b8440e..91d2ecf 100644 (file)
@@ -338,6 +338,8 @@ uint32 freerdp_keyboard_init_xkb(uint32 keyboardLayoutId)
 
        freerdp_keyboard_load_map_from_xkb(display);
 
+       XCloseDisplay(display);
+
        return keyboardLayoutId;
 }
 
index 8351d04..05fc597 100644 (file)
@@ -90,17 +90,16 @@ char* freerdp_get_home_path(rdpSettings* settings)
 
 char* freerdp_get_config_path(rdpSettings* settings)
 {
-       char* path;
-
-       path = (char*) xmalloc(strlen(settings->home_path) + sizeof(FREERDP_CONFIG_DIR) + 2);
-       sprintf(path, "%s/%s", settings->home_path, FREERDP_CONFIG_DIR);
+       if (settings->config_path != NULL)
+               return settings->config_path;
 
-       if (!freerdp_check_file_exists(path))
-               freerdp_mkdir(path);
+       settings->config_path = (char*) xmalloc(strlen(settings->home_path) + sizeof(FREERDP_CONFIG_DIR) + 2);
+       sprintf(settings->config_path, "%s/%s", settings->home_path, FREERDP_CONFIG_DIR);
 
-       settings->config_path = path;
+       if (!freerdp_check_file_exists(settings->config_path))
+               freerdp_mkdir(settings->config_path);
 
-       return path;
+       return settings->config_path;
 }
 
 char* freerdp_get_current_path(rdpSettings* settings)