From 997d32e9cdd21476b452c6de6ffb99e37e902324 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Fri, 10 May 2024 18:01:52 +0200 Subject: [PATCH] girepository/girparser: Free the struct or union node if was not tracked In case the node was pushed to a non-empty node stack, then we were not tracking it in the entries list, and so nothing was freeing it on destruction. As per this, once parsing is done, we can free it or we'd leak. --- girepository/girparser.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/girepository/girparser.c b/girepository/girparser.c index f0c578fd4..046ba2f98 100644 --- a/girepository/girparser.c +++ b/girepository/girparser.c @@ -3376,13 +3376,19 @@ state_switch_end_struct_or_union (GMarkupParseContext *context, const char *element_name, GError **error) { - pop_node (ctx); + GIIrNode *node = pop_node (ctx); + if (ctx->node_stack == NULL) { state_switch (ctx, STATE_NAMESPACE); } else { + /* In this case the node was not tracked by any other node, so we need + * to free the node, or we'd leak. + */ + g_clear_pointer (&node, gi_ir_node_free); + if (CURRENT_NODE (ctx)->type == GI_IR_NODE_STRUCT) state_switch (ctx, STATE_STRUCT); else if (CURRENT_NODE (ctx)->type == GI_IR_NODE_UNION)