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:
Steffen Jaeckel
2023-01-09 18:00:47 +01:00
parent 1a85448bf2
commit b535921484
3 changed files with 36 additions and 26 deletions

View File

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