[libgdata/wip/oholy/gdata-entry-get-id-fix] core: Don't always free the current id string in gdata_entry_get_id()



commit 7229cdabff7e9b4e2174b2de0669957665de63f0
Author: Ondrej Holy <oholy redhat com>
Date:   Tue Jul 23 12:51:52 2019 +0200

    core: Don't always free the current id string in gdata_entry_get_id()
    
    Currently, if you call gdata_entry_get_id() for the second time, the first
    returned id string is released even if the id hasn't been changed. This is
    unexpected and causes issues in several places of gvfsbackendgoogle.c, where
    g_strdup() has to be used as a workaround to prevent segfaults. Let's change
    the behavior to not free the current id, if it was not changed.
    
    Closes: https://gitlab.gnome.org/GNOME/libgdata/issues/31

 gdata/gdata-entry.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
---
diff --git a/gdata/gdata-entry.c b/gdata/gdata-entry.c
index 2d84bc63..4a4f35a5 100644
--- a/gdata/gdata-entry.c
+++ b/gdata/gdata-entry.c
@@ -787,11 +787,14 @@ gdata_entry_get_id (GDataEntry *self)
        /* We have to get the actual property since GDataDocumentsEntry overrides it. We then store it in our 
own ID field so that we can
         * free it later on. */
        g_object_get (G_OBJECT (self), "id", &id, NULL);
+       if (g_strcmp0 (id, self->priv->id) != 0) {
+               g_free (self->priv->id);
+               self->priv->id = id;
+       } else {
+               g_free (id);
+       }
 
-       g_free (self->priv->id);
-       self->priv->id = id;
-
-       return id;
+       return self->priv->id;
 }
 
 /**


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