[mutter] x11/xprops: Plug a few memory leaks



commit 5ba38a4ab6913fc5a4005ec3195df6bff5e89821
Author: Rui Matos <tiagomatos gmail com>
Date:   Tue Feb 21 15:49:09 2017 +0100

    x11/xprops: Plug a few memory leaks
    
    Commits 6dbec6f8, 734402e1 and f041b35b introduced memory leaks by
    switching to returning copies instead of the original buffers but
    forgetting to free those original buffers.
    
    Some error cases were also not freeing the ->prop buffer as they
    should.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=642652

 src/x11/xprops.c |   24 ++++++++++++++++++++++--
 1 files changed, 22 insertions(+), 2 deletions(-)
---
diff --git a/src/x11/xprops.c b/src/x11/xprops.c
index e3bd931..cffa595 100644
--- a/src/x11/xprops.c
+++ b/src/x11/xprops.c
@@ -304,6 +304,8 @@ motif_hints_from_results (GetPropertyResults *results,
 
   if (results->type == None || results->n_items <= 0)
     {
+      g_free (results->prop);
+      results->prop = NULL;
       meta_verbose ("Motif hints had unexpected type or n_items\n");
       return FALSE;
     }
@@ -314,10 +316,18 @@ motif_hints_from_results (GetPropertyResults *results,
    */
   *hints_p = calloc (1, sizeof (MotifWmHints));
   if (*hints_p == NULL)
-    return FALSE;
+    {
+      g_free (results->prop);
+      results->prop = NULL;
+      return FALSE;
+    }
 
   memcpy(*hints_p, results->prop, MIN (sizeof (MotifWmHints),
                                        results->n_items * sizeof (uint32_t)));
+
+  g_free (results->prop);
+  results->prop = NULL;
+
   return TRUE;
 }
 
@@ -349,6 +359,9 @@ latin1_string_from_results (GetPropertyResults *results,
 
   *str_p = g_strndup ((char *) results->prop, results->n_items);
 
+  g_free (results->prop);
+  results->prop = NULL;
+
   return TRUE;
 }
 
@@ -396,6 +409,9 @@ utf8_string_from_results (GetPropertyResults *results,
 
   *str_p = g_strndup ((char *) results->prop, results->n_items);
 
+  g_free (results->prop);
+  results->prop = NULL;
+
   return TRUE;
 }
 
@@ -772,7 +788,11 @@ size_hints_from_results (GetPropertyResults *results,
     return FALSE;
 
   if (results->n_items < OldNumPropSizeElements)
-    return FALSE;
+    {
+      g_free (results->prop);
+      results->prop = NULL;
+      return FALSE;
+    }
 
   raw = (xPropSizeHints*) results->prop;
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]