[glib] GOption: fix bug in strv mode



commit 7f36233042691d942982c4e6c4ea16f7e27aeb6b
Author: Ryan Lortie <desrt desrt ca>
Date:   Wed Feb 5 17:11:50 2014 +0000

    GOption: fix bug in strv mode
    
    We are a bit too aggressive about freeing memory in strv mode.  Only
    free it in the case that we actually set the pointer to NULL.
    
    Uncovered by the GApplication tests.

 glib/goption.c |   10 ++++++----
 1 files changed, 6 insertions(+), 4 deletions(-)
---
diff --git a/glib/goption.c b/glib/goption.c
index f017892..da04596 100644
--- a/glib/goption.c
+++ b/glib/goption.c
@@ -1717,9 +1717,6 @@ free_pending_nulls (GOptionContext *context,
 
       if (perform_nulls)
         {
-          if (context->strv_mode)
-            g_free (*n->ptr);
-
           if (n->value)
             {
               /* Copy back the short options */
@@ -1727,7 +1724,12 @@ free_pending_nulls (GOptionContext *context,
               strcpy (*n->ptr + 1, n->value);
             }
           else
-            *n->ptr = NULL;
+            {
+              if (context->strv_mode)
+                g_free (*n->ptr);
+
+              *n->ptr = NULL;
+            }
         }
 
       g_free (n->value);


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