Description: Hack dynamic loader to workaround libopenh323 bug
 libopenh323 is buggy and crashes on dlclose() when the library was
 opened with RTLD_LAZY (#438815). Hack around this by opening it with
 RTLD_NOW by matching the module names (chan_h323.so and the external
 chan_oh323.so)
 .
 This is a very crude hack needed because we are removing libopenh323
 dependencies from the asterisk binary. (h323-no-deps-on-asterisk)
 Namely, it will have unexpected results if e.g. the user renames the
 module for any reason.
 .
 Should be removed when #438815 closes.
Author: Faidon Liambotis <paravoid@debian.org>
Bug-Debian: https://bugs.debian.org/435146
Forwarded: no
Last-Update: 2016-03-19

--- a/main/loader.c
+++ b/main/loader.c
@@ -382,6 +382,12 @@
 	if (missing_so)
 		strcat(resource_being_loaded->resource, ".so");
 
+	/* libopenh323 is buggy and segfaults on dlclose() when opened with
+	 * RTLD_LAZY. Workaround this until it gets fixed */
+	if (!strcasecmp(resource_being_loaded->resource, "chan_h323.so") ||
+	    !strcasecmp(resource_being_loaded->resource, "chan_oh323.so"))
+		lib = dlopen(fn, RTLD_NOW | RTLD_LOCAL);
+
 	if (!(lib = dlopen(fn, RTLD_LAZY | RTLD_LOCAL))) {
 		ast_log(LOG_WARNING, "Error loading module '%s': %s\n", resource_in, dlerror());
 		ast_free(resource_being_loaded);
