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/
PYTHON3 = dependency('', required: false)
if get_option('python3')
if not get_option('introspection')
error('Python3 plugin requires GObject Introspection.')
endif
GPLUGIN_PYTHON3_SOURCES = [
'gplugin-python3-core.c',
'gplugin-python3-loader.c',
'gplugin-python3-plugin.c',
'gplugin-python3-utils.c',
]
GPLUGIN_PYTHON3_HEADERS = [
'gplugin-python3-loader.h',
'gplugin-python3-plugin.h',
'gplugin-python3-utils.h',
]
PYGOBJECT = dependency('pygobject-3.0', version: '>=3.0.0')
_PYTHONS = [
['python-3.11-embed', '>=3.11'],
['python-3.10-embed', '>=3.10'],
['python-3.9-embed', '>=3.9'],
['python-3.8-embed', '>=3.8'],
['python3-embed', '>=3.8'],
['python3', '>=3.8'],
['python-3.7', '>=3.7'],
['python-3.7m', '>=3.7'],
]
PYGOBJECT_WORKS = false
foreach _PYTHON : _PYTHONS
PYTHON3 = dependency(_PYTHON[0], version : _PYTHON[1], required : false)
if PYTHON3.found()
python3_gi_test = compiler.run(files('gplugin-python3-test-pygobject.c'),
dependencies : [GLIB, PYTHON3, PYGOBJECT],
name : 'Python3 GI')
if not python3_gi_test.compiled() or python3_gi_test.returncode() != 0
message('pygobject does not work with @0@'.format(_PYTHON[0]))
continue
endif
PYGOBJECT_WORKS = true
break
endif
endforeach
if not PYTHON3.found()
error('failed to find a usable python')
endif
if not PYGOBJECT_WORKS
error('found a usable python but pygobject does not work with it')
endif
endif # python3
summary('Python3', PYTHON3, section : 'Loader Support', bool_yn : true)
if not PYTHON3.found()
subdir_done()
endif
# Now add our libraries
gplugin_python3_inc = include_directories('.')
gplugin_python3 = shared_library('gplugin-python3',
GPLUGIN_PYTHON3_SOURCES,
GPLUGIN_PYTHON3_HEADERS,
name_prefix : '',
c_args : ['-DG_LOG_USE_STRUCTURED', '-DG_LOG_DOMAIN="GPlugin-Python3"'],
dependencies : [PYTHON3, PYGOBJECT, gplugin_dep],
install : true,
install_dir : get_option('libdir') / 'gplugin'
)
gplugin_python3_dep = declare_dependency(
include_directories : gplugin_python3_inc,
link_with : gplugin_python3,
)
gplugin_python3_static = static_library('gplugin-python3-static',
GPLUGIN_PYTHON3_SOURCES,
GPLUGIN_PYTHON3_HEADERS,
dependencies : [PYTHON3, PYGOBJECT, gplugin_dep],
)
gplugin_python3_static_dep = declare_dependency(
include_directories : gplugin_python3_inc,
link_with : gplugin_python3_static,
)
# Add the loader's path to our environment variable
devenv.append('GPLUGIN_PLUGIN_PATH', meson.current_build_dir())
subdir('tests')