parser: fix memory leak in error path for depth more than 1

If parser has an unfinished stanza with depth > 1, it can happen that
parser->stanza points to a child. Releasing the child doesn't free the
parent stanza.

Instead of releasing parser->stanza in parser_reset() and parser_free(),
find the top most parent and release the whole tree. Also add a test
case for this memory leak.
This commit is contained in:
Dmitry Podgorny
2021-06-27 03:24:42 +03:00
parent 05620ab506
commit 2bf1988b3c
3 changed files with 30 additions and 3 deletions

View File

@@ -110,6 +110,10 @@ static void test_stanza_from_string(xmpp_ctx_t *ctx)
assert(strcmp(buf, str) == 0);
xmpp_free(ctx, buf);
xmpp_stanza_release(stanza);
/* Error path. */
stanza = xmpp_stanza_new_from_string(ctx, "<uu><uu>tt");
assert(stanza == NULL);
}
int main()