From ae489acc93226c968c43f7f6f02e8c42ffbea8bb Mon Sep 17 00:00:00 2001 From: Philipp Schafft Date: Fri, 8 Jun 2018 08:47:37 +0000 Subject: [PATCH] Fix: Ensure references are counted correctly in case reportxml_node_copy() fails --- src/reportxml.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/reportxml.c b/src/reportxml.c index fcd242ef..991e3041 100644 --- a/src/reportxml.c +++ b/src/reportxml.c @@ -440,15 +440,18 @@ reportxml_node_t * reportxml_node_copy(reportxml_node_t *node) } for (i = 0; i < (size_t)count; i++) { - reportxml_node_t *child = reportxml_node_copy(reportxml_node_get_child(node, i)); + reportxml_node_t *child = reportxml_node_get_child(node, i); + reportxml_node_t *copy = reportxml_node_copy(child); - if (!child) { + refobject_unref(child); + + if (!copy) { refobject_unref(ret); return NULL; } - if (reportxml_node_add_child(ret, child) != 0) { - refobject_unref(child); + if (reportxml_node_add_child(ret, copy) != 0) { + refobject_unref(copy); refobject_unref(ret); return NULL; }