diff options
author | Stefano Garzarella <sgarzare@redhat.com> | 2019-02-27 12:25:20 +0100 |
---|---|---|
committer | Daiki Ueno <ueno@gnu.org> | 2019-02-27 14:39:57 +0100 |
commit | 4a925177a81c2566d2a81a0a450607a5ff4d9048 (patch) | |
tree | 2fd2a2aa0a69443b4fc628fa9071a7d9fa6f5be8 /p11-kit | |
parent | e2170b295992cb7fdf115227a78028ac3780619f (diff) |
modules: check gl.modules before iterates on it when freeing
In some circumstances, as described in the BZ, can happen that
free_modules_when_no_refs_unlocked() is called multiple times
when the module destructor is invoked.
We should check gl.modules before iterates on it in the
free_modules_when_no_refs_unlocked() functions, to avoid
a SIGSEGV.
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1680963
Diffstat (limited to 'p11-kit')
-rw-r--r-- | p11-kit/modules.c | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/p11-kit/modules.c b/p11-kit/modules.c index 0299eda..891ce4c 100644 --- a/p11-kit/modules.c +++ b/p11-kit/modules.c @@ -797,14 +797,16 @@ init_globals_unlocked (void) static void free_modules_when_no_refs_unlocked (void) { - Module *mod; - p11_dictiter iter; - - /* Check if any modules have a ref count */ - p11_dict_iterate (gl.modules, &iter); - while (p11_dict_next (&iter, (void **)&mod, NULL)) { - if (mod->ref_count) - return; + if (gl.modules) { + Module *mod; + p11_dictiter iter; + + /* Check if any modules have a ref count */ + p11_dict_iterate (gl.modules, &iter); + while (p11_dict_next (&iter, (void **)&mod, NULL)) { + if (mod->ref_count) + return; + } } p11_dict_free (gl.unmanaged_by_funcs); |