grim/pidgin

Fix leaks when loading accounts

16 months ago, Elliott Sales de Andrade
08966165974c
Parents 33ed4a2a7593
Children e431d160e3a1
Fix leaks when loading accounts

Fix two leaks in account parser:
```
512 bytes in 4 blocks are definitely lost in loss record 30,342 of 33,863
at 0x484378A: malloc (vg_replace_malloc.c:392)
by 0x484870B: realloc (vg_replace_malloc.c:1451)
by 0x498071F: g_realloc (gmem.c:201)
by 0x499A343: g_string_maybe_expand (gstring.c:92)
by 0x499A3BF: g_string_sized_new (gstring.c:116)
by 0x499A7AA: UnknownInlinedFun (gstring.c:176)
by 0x499A7AA: g_string_new_len (gstring.c:167)
by 0x4D577C6: purple_xmlnode_get_data (xmlnode.c:460)
by 0x4CCD5D8: parse_account (accounts.c:338)
by 0x4CCD98B: load_accounts (accounts.c:449)
by 0x4CCE234: purple_accounts_init (accounts.c:667)
by 0x4CE3AC2: purple_core_init (core.c:174)
by 0x48A380A: pidgin_application_startup (pidginapplication.c:820)

512 bytes in 4 blocks are definitely lost in loss record 30,343 of 33,863
at 0x484378A: malloc (vg_replace_malloc.c:392)
by 0x484870B: realloc (vg_replace_malloc.c:1451)
by 0x498071F: g_realloc (gmem.c:201)
by 0x499A343: g_string_maybe_expand (gstring.c:92)
by 0x499A3BF: g_string_sized_new (gstring.c:116)
by 0x499A7AA: UnknownInlinedFun (gstring.c:176)
by 0x499A7AA: g_string_new_len (gstring.c:167)
by 0x4D577C6: purple_xmlnode_get_data (xmlnode.c:460)
by 0x4CCD610: parse_account (accounts.c:343)
by 0x4CCD98B: load_accounts (accounts.c:449)
by 0x4CCE234: purple_accounts_init (accounts.c:667)
by 0x4CE3AC2: purple_core_init (core.c:174)
by 0x48A380A: pidgin_application_startup (pidginapplication.c:820)
```
and one in the demo protocol:
```
16,008 (56 direct, 15,952 indirect) bytes in 1 blocks are definitely lost in loss record 33,622 of 33,863
at 0x4DDF1EF: g_type_create_instance (gtype.c:1909)
by 0x4DC4C1F: g_object_new_internal (gobject.c:2228)
by 0x4DC6972: g_object_new_valist (gobject.c:2567)
by 0x4DC6FCC: g_object_new (gobject.c:2040)
by 0x57CF444: g_resource_open_stream (gresource.c:764)
by 0x1CAA54A2: purple_demo_contacts_load (purpledemocontacts.c:233)
by 0x1CAA4CD0: purple_demo_connection_connect (purpledemoconnection.c:43)
by 0x4CE1540: purple_connection_connect (connection.c:955)
by 0x4CC7F5E: purple_account_real_connect (account.c:179)
by 0x4CC85B0: no_password_cb (account.c:355)
by 0x49784C7: g_timeout_dispatch (gmain.c:5007)
by 0x4977CBE: UnknownInlinedFun (gmain.c:3444)
by 0x4977CBE: g_main_context_dispatch (gmain.c:4162)
```

Testing Done:
Ran in valgrind and confirmed above leaks were gone.

Reviewed at https://reviews.imfreedom.org/r/2299/
--- a/libpurple/accounts.c Tue Feb 28 03:21:35 2023 -0600
+++ b/libpurple/accounts.c Tue Feb 28 03:22:13 2023 -0600
@@ -335,12 +335,16 @@
child = purple_xmlnode_get_child(node, "require_password");
if(child != NULL) {
- require_password = atoi(purple_xmlnode_get_data(child));
+ data = purple_xmlnode_get_data(child);
+ require_password = atoi(data);
+ g_free(data);
}
child = purple_xmlnode_get_child(node, "enabled");
if(child != NULL) {
- enabled = atoi(purple_xmlnode_get_data(child));
+ data = purple_xmlnode_get_data(child);
+ enabled = atoi(data);
+ g_free(data);
}
if ((protocol_id == NULL) || (name == NULL))
--- a/libpurple/protocols/demo/purpledemocontacts.c Tue Feb 28 03:21:35 2023 -0600
+++ b/libpurple/protocols/demo/purpledemocontacts.c Tue Feb 28 03:22:13 2023 -0600
@@ -252,4 +252,5 @@
g_clear_object(&parser);
g_input_stream_close(istream, NULL, NULL);
+ g_object_unref(istream);
}