From e475ca13ea7b4a98d9f5cb51598eed818fdc7c2f Mon Sep 17 00:00:00 2001 From: Dmitry Podgorny Date: Wed, 21 Oct 2015 02:11:03 +0300 Subject: [PATCH] stanza: handle errors better * Free memory on error in xmpp_stanza_set_attribute() * Handle memory allocation error in xmpp_stanza_set_text() --- src/stanza.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/stanza.c b/src/stanza.c index a3783bc..0d5c1ae 100644 --- a/src/stanza.c +++ b/src/stanza.c @@ -583,7 +583,10 @@ int xmpp_stanza_set_attribute(xmpp_stanza_t * const stanza, } val = xmpp_strdup(stanza->ctx, value); - if (!val) return XMPP_EMEM; + if (!val) { + hash_release(stanza->attributes); + return XMPP_EMEM; + } hash_add(stanza->attributes, key, val); @@ -662,7 +665,7 @@ int xmpp_stanza_set_text(xmpp_stanza_t *stanza, if (stanza->data) xmpp_free(stanza->ctx, stanza->data); stanza->data = xmpp_strdup(stanza->ctx, text); - return XMPP_EOK; + return stanza->data == NULL ? XMPP_EMEM : XMPP_EOK; } /** Set the text data for a text stanza.