pidgin/pidgin

Fix leaks when loading accounts

14 months ago, Elliott Sales de Andrade
08966165974c
file isExecutable
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/
#!/usr/bin/env python3
#
# Purple is the legal property of its developers, whose names are too numerous
# to list here. Please refer to the COPYRIGHT file distributed with this
# source distribution.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
"""
Produce meson-config.h in a build directory.
This should not really be run manually. It is used by Meson as a
post-configuration script to create meson-config.h which for now simply
contains information about the configuration used to create the build
directory.
"""
import html
import json
import os
import shlex
import subprocess
import sys
try:
introspect = os.environ['MESONINTROSPECT']
except KeyError:
print('Meson is too old; '
'it does not set MESONINTROSPECT for postconf scripts.')
sys.exit(1)
else:
introspect = shlex.split(introspect)
try:
build_root = os.environ['MESON_BUILD_ROOT']
except KeyError:
print('Meson is too old; '
'it does not set MESON_BUILD_ROOT for postconf scripts.')
sys.exit(1)
def tostr(obj):
if isinstance(obj, str):
return html.escape(repr(obj))
else:
return repr(obj)
conf = subprocess.check_output(introspect + ['--buildoptions', build_root],
universal_newlines=True)
conf = json.loads(conf)
settings = ' '.join('{}={}'.format(option['name'], tostr(option['value']))
for option in sorted(conf, key=lambda x: x['name']))
with open(os.path.join(build_root, 'meson-config.h'), 'w') as f:
f.write('#define MESON_ARGS "{}"'.format(settings))