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.
This commit is contained in:
Marco Trevisan (Treviño) 2024-05-10 18:01:52 +02:00 committed by Philip Withnall
parent 98dce8a1c6
commit 997d32e9cd

View File

@ -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)