[librsvg] Ref the found node when iterating through children to find a specific node



commit 21b181b948433cae9477541b74479a08f386ee65
Author: Federico Mena Quintero <federico gnome org>
Date:   Thu Feb 16 23:17:31 2017 -0600

    Ref the found node when iterating through children to find a specific node
    
    The callback from rsvg_node_foreach_child() does not get to keep the
    child reference anymore; it has to ref() it.

 rsvg-base.c   |    3 ++-
 rsvg-filter.c |    9 +++++++--
 2 files changed, 9 insertions(+), 3 deletions(-)
---
diff --git a/rsvg-base.c b/rsvg-base.c
index 66137de..59198e9 100644
--- a/rsvg-base.c
+++ b/rsvg-base.c
@@ -912,7 +912,7 @@ find_last_chars_node (RsvgNode *node, gpointer data)
     dest = data;
 
     if (rsvg_node_get_type (node) == RSVG_NODE_TYPE_CHARS) {
-        *dest = node;
+        *dest = rsvg_node_ref (node);
     } else if (rsvg_node_get_type (node) == RSVG_NODE_TYPE_TSPAN) {
         *dest = NULL;
     }
@@ -953,6 +953,7 @@ rsvg_characters_impl (RsvgHandle * ctx, const xmlChar * ch, int len)
                     g_string_append_len (self->contents, (char *)ch, len);
                 }
 
+                node = rsvg_node_unref (node);
                 return;
             }
         }
diff --git a/rsvg-filter.c b/rsvg-filter.c
index 3096a3c..4c6fc9a 100644
--- a/rsvg-filter.c
+++ b/rsvg-filter.c
@@ -4434,7 +4434,7 @@ is_light_source (RsvgNode *node, gpointer data)
     struct find_light_source_closure *closure = data;
 
     if (rsvg_node_get_type (node) == RSVG_NODE_TYPE_LIGHT_SOURCE) {
-        closure->found_node = node;
+        closure->found_node = rsvg_node_ref (node);
     }
 
     return TRUE;
@@ -4444,6 +4444,7 @@ static RsvgNodeLightSource *
 find_light_source_in_children (RsvgNode *node)
 {
     struct find_light_source_closure closure;
+    RsvgNodeLightSource *source;
 
     closure.found_node = NULL;
     rsvg_node_foreach_child (node, is_light_source, &closure);
@@ -4451,7 +4452,11 @@ find_light_source_in_children (RsvgNode *node)
         return NULL;
 
     g_assert (rsvg_node_get_type (closure.found_node) == RSVG_NODE_TYPE_LIGHT_SOURCE);
-    return rsvg_rust_cnode_get_impl (closure.found_node);
+
+    source = rsvg_rust_cnode_get_impl (closure.found_node);
+    closure.found_node = rsvg_node_unref (closure.found_node);
+
+    return source;
 }
 
 static void


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