gplugin/gplugin

fix memory leaks in gplugin_file_source

14 months ago, Markus Fischer
d821f171d4c6
fix memory leaks in gplugin_file_source

leaks encountered:
## libpurple test_contact_info and test_person
```
==5998== 16 bytes in 1 blocks are definitely lost in loss record 1,996 of 6,277
==5998== at 0x48417E4: malloc (vg_replace_malloc.c:393)
==5998== by 0x4A6FA18: g_malloc (in /usr/lib64/libglib-2.0.so.0.7400.4)
==5998== by 0x4A88540: g_slice_alloc (in /usr/lib64/libglib-2.0.so.0.7400.4)
==5998== by 0x4A89675: g_slist_prepend (in /usr/lib64/libglib-2.0.so.0.7400.4)
==5998== by 0x4F0DA9E: gplugin_file_source_add_loader (gplugin-file-source.c:112)
==5998== by 0x4F0DCF1: gplugin_file_source_update_loaders (gplugin-file-source.c:179)
==5998== by 0x4F0E971: gplugin_file_source_constructed (gplugin-file-source.c:524)
==5998== by 0x49CF002: ??? (in /usr/lib64/libgobject-2.0.so.0.7400.4)
==5998== by 0x49D0C33: g_object_new_valist (in /usr/lib64/libgobject-2.0.so.0.7400.4)
==5998== by 0x49D1250: g_object_new (in /usr/lib64/libgobject-2.0.so.0.7400.4)
==5998== by 0x4F0EC51: gplugin_file_source_new (gplugin-file-source.c:607)
==5998== by 0x4F08019: gplugin_manager_refresh (gplugin-manager.c:874)
```
## gplugin tests
```
==23357== 456 (16 direct, 440 indirect) bytes in 1 blocks are definitely lost in loss record 535 of 557
==23357== at 0x48417E4: malloc (vg_replace_malloc.c:393)
==23357== by 0x48E4828: g_malloc (in /usr/lib64/libglib-2.0.so.0.7400.5)
==23357== by 0x48FD281: g_slice_alloc (in /usr/lib64/libglib-2.0.so.0.7400.5)
==23357== by 0x48FE6A8: g_slist_copy_deep (in /usr/lib64/libglib-2.0.so.0.7400.5)
==23357== by 0x485B252: gplugin_manager_find_plugins (gplugin-manager.c:934)
==23357== by 0x4861216: gplugin_file_source_scan (gplugin-file-source.c:349)
==23357== by 0x48622A9: gplugin_source_scan (gplugin-source.c:66)
==23357== by 0x485B041: gplugin_manager_refresh (gplugin-manager.c:881)
==23357== by 0x109464: test_gplugin_init_uninit_with_double_refresh_plugins (test-core.c:115)
==23357== by 0x49079DD: ??? (in /usr/lib64/libglib-2.0.so.0.7400.5)
==23357== by 0x490774C: ??? (in /usr/lib64/libglib-2.0.so.0.7400.5)
==23357== by 0x4907EE1: g_test_run_suite (in /usr/lib64/libglib-2.0.so.0.7400.5)
```

Testing Done:
Ran all gplugin tests and test_contact_info and test_person from libpurple in valgrind without encountering above leaks or any invalid reads/writes.

Reviewed at https://reviews.imfreedom.org/r/2255/
###############################################################################
# Project Info
###############################################################################
project('gplugin', 'c',
license : 'LGPL-2.0-or-later',
version : '0.39.2-dev',
meson_version : '>=0.61.0',
default_options : ['c_std=c99', 'warning_level=2'])
parts = meson.project_version().split('-')
if parts.length() > 1
extra = parts[1]
else
extra = ''
endif
parts = parts[0].split('.')
GPLUGIN_MAJOR_VERSION = parts[0]
version_conf = configuration_data()
version_conf.set('GPLUGIN_MAJOR_VERSION', GPLUGIN_MAJOR_VERSION)
version_conf.set('GPLUGIN_MINOR_VERSION', parts[1])
version_conf.set('GPLUGIN_MICRO_VERSION', parts[2])
version_conf.set('GPLUGIN_EXTRA_VERSION', extra)
version_conf.set('GPLUGIN_VERSION', meson.project_version())
###############################################################################
# Dependencies
###############################################################################
gnome = import('gnome')
pkgconfig = import('pkgconfig')
if get_option('help2man')
help2man = find_program('help2man')
endif
GLIB = dependency('glib-2.0', version : '>=2.70.0')
GOBJECT = dependency('gobject-2.0')
# we separate gmodule out so our test aren't linked to it
GMODULE = dependency('gmodule-2.0')
add_project_arguments(
'-DGLIB_VERSION_MIN_REQUIRED=GLIB_VERSION_2_70',
'-DGLIB_VERSION_MAX_ALLOWED=GLIB_VERSION_2_70',
language : 'c',
)
###############################################################################
# devenv
#
# This sets up the meson devenv stuff. See
# https://mesonbuild.com/Commands.html#devenv for more information.
###############################################################################
devenv = environment()
config_home = get_option('devenv-config-dir')
if config_home == ''
config_home = meson.project_build_root() / 'config'
endif
devenv.set('XDG_CONFIG_HOME', config_home)
meson.add_devenv(devenv)
###############################################################################
# NLS
###############################################################################
GETTEXT_PACKAGE = 'gplugin'
LOCALE_DIR = get_option('prefix') / get_option('localedir')
add_project_arguments(f'-DLOCALEDIR="@LOCALE_DIR@"', language : 'c')
add_project_arguments(f'-DGETTEXT_PACKAGE="@GETTEXT_PACKAGE@"', language : 'c')
if get_option('nls')
i18n = import('i18n')
endif
###############################################################################
# Build Info
###############################################################################
compiler = meson.get_compiler('c')
add_project_arguments(
'-DPREFIX="@0@"'.format(get_option('prefix')),
'-DLIBDIR="@0@"'.format(get_option('libdir')),
'-DGPLUGIN_WEBSITE="https://keep.imfreedom.org/gplugin/gplugin"',
language : 'c'
)
if compiler.has_argument('-Wformat')
add_project_arguments('-Wformat', language : 'c')
if compiler.has_multi_arguments(['-Wformat', '-Werror=format-security'])
add_project_arguments('-Werror=format-security', language : 'c')
endif
endif
toplevel_inc = include_directories('.')
###############################################################################
# Documentation
###############################################################################
if get_option('doc') and not get_option('introspection')
error('Documentation requires GObject Introspection.')
endif
gidocgen_dep = dependency(
'gi-docgen', version: '>= 2021.1',
fallback: ['gi-docgen', 'dummy_dep'],
required: get_option('doc')
)
gidocgen = find_program('gi-docgen', required : get_option('doc'))
docs_dir = get_option('prefix') / get_option('datadir') / 'doc'
doc_targets = []
###############################################################################
# Subdirectories
###############################################################################
subdir('gplugin')
subdir('gplugin-gtk4')
subdir('gplugin-gtk4-viewer', if_found: GTK4)
subdir('gplugin-query')
subdir('po')
subdir('lua')
subdir('python3')
subdir('vala')
if get_option('doc')
alias_target('doc', doc_targets)
endif
###############################################################################
# Install stuff
###############################################################################
# documentation
install_data('ChangeLog', 'INSTALL.md', 'README.md', 'HACKING.md',
install_dir : get_option('datadir') / 'doc' / 'gplugin')
summary({
'api reference' : get_option('doc'),
'GTK4 widgets' : GTK4,
'man pages' : get_option('help2man'),
}, bool_yn : true, section : 'Miscellaneous')
summary({
'introspection' : get_option('introspection'),
'vapi' : get_option('vapi'),
}, bool_yn : true, section : 'Bindings')