introduce auto_jid and refcounting in Jid
This also fixes a memory leak from within `_handle_groupchat()` in [0]. [0] src/xmpp/message.c Signed-off-by: Steffen Jaeckel <jaeckel-floss@eyet-services.de>
This commit is contained in:
@@ -76,6 +76,7 @@ jid_create(const gchar* const str)
|
||||
result->resourcepart = NULL;
|
||||
result->barejid = NULL;
|
||||
result->fulljid = NULL;
|
||||
result->refcnt = 1;
|
||||
|
||||
gchar* atp = g_utf8_strchr(trimmed, -1, '@');
|
||||
gchar* slashp = g_utf8_strchr(trimmed, -1, '/');
|
||||
@@ -119,12 +120,30 @@ jid_create_from_bare_and_resource(const char* const barejid, const char* const r
|
||||
return result;
|
||||
}
|
||||
|
||||
void
|
||||
jid_auto_destroy(Jid** jid)
|
||||
{
|
||||
if (jid == NULL)
|
||||
return;
|
||||
jid_destroy(*jid);
|
||||
}
|
||||
|
||||
void
|
||||
jid_ref(Jid* jid)
|
||||
{
|
||||
jid->refcnt++;
|
||||
}
|
||||
|
||||
void
|
||||
jid_destroy(Jid* jid)
|
||||
{
|
||||
if (jid == NULL) {
|
||||
return;
|
||||
}
|
||||
if (jid->refcnt > 1) {
|
||||
jid->refcnt--;
|
||||
return;
|
||||
}
|
||||
|
||||
g_free(jid->str);
|
||||
g_free(jid->localpart);
|
||||
|
||||
Reference in New Issue
Block a user