Fix for refcount handling in stanzas, by Jack.
This commit is contained in:
27
src/stanza.c
27
src/stanza.c
@@ -62,8 +62,7 @@ xmpp_stanza_t *xmpp_stanza_new(xmpp_ctx_t *ctx)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Clone a stanza object.
|
/** Clone a stanza object.
|
||||||
* This function increments the reference count of the stanza and all its
|
* This function increments the reference count of the stanza object.
|
||||||
* children.
|
|
||||||
*
|
*
|
||||||
* @param stanza a Strophe stanza object
|
* @param stanza a Strophe stanza object
|
||||||
*
|
*
|
||||||
@@ -77,10 +76,6 @@ xmpp_stanza_t *xmpp_stanza_clone(xmpp_stanza_t * const stanza)
|
|||||||
|
|
||||||
stanza->ref++;
|
stanza->ref++;
|
||||||
|
|
||||||
/* clone all children */
|
|
||||||
for (child = stanza->children; child; child = child->next)
|
|
||||||
xmpp_stanza_clone(child);
|
|
||||||
|
|
||||||
return stanza;
|
return stanza;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -152,8 +147,8 @@ copy_error:
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Release a stanza object and all of its children.
|
/** Release a stanza object and all of its children.
|
||||||
* This function releases a stanza object and all of its children, which may
|
* This function releases a stanza object and potentially all of its
|
||||||
* cause the object to be freed.
|
* children, which may cause the object(s) to be freed.
|
||||||
*
|
*
|
||||||
* @param stanza a Strophe stanza object
|
* @param stanza a Strophe stanza object
|
||||||
*
|
*
|
||||||
@@ -166,18 +161,18 @@ int xmpp_stanza_release(xmpp_stanza_t * const stanza)
|
|||||||
int released = 0;
|
int released = 0;
|
||||||
xmpp_stanza_t *child, *tchild;
|
xmpp_stanza_t *child, *tchild;
|
||||||
|
|
||||||
/* release all children */
|
|
||||||
child = stanza->children;
|
|
||||||
while (child) {
|
|
||||||
tchild = child;
|
|
||||||
child = child->next;
|
|
||||||
xmpp_stanza_release(tchild);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* release stanza */
|
/* release stanza */
|
||||||
if (stanza->ref > 1)
|
if (stanza->ref > 1)
|
||||||
stanza->ref--;
|
stanza->ref--;
|
||||||
else {
|
else {
|
||||||
|
/* release all children */
|
||||||
|
child = stanza->children;
|
||||||
|
while (child) {
|
||||||
|
tchild = child;
|
||||||
|
child = child->next;
|
||||||
|
xmpp_stanza_release(tchild);
|
||||||
|
}
|
||||||
|
|
||||||
if (stanza->attributes) hash_release(stanza->attributes);
|
if (stanza->attributes) hash_release(stanza->attributes);
|
||||||
if (stanza->data) xmpp_free(stanza->ctx, stanza->data);
|
if (stanza->data) xmpp_free(stanza->ctx, stanza->data);
|
||||||
xmpp_free(stanza->ctx, stanza);
|
xmpp_free(stanza->ctx, stanza);
|
||||||
|
|||||||
Reference in New Issue
Block a user