[evolution-data-server/gnome-3-26] Initialize libxml2 global memory in the main()
- From: Milan Crha <mcrha src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution-data-server/gnome-3-26] Initialize libxml2 global memory in the main()
- Date: Wed, 4 Oct 2017 07:47:00 +0000 (UTC)
commit da9497356353a274f83e91a98eab9d7217567b7c
Author: Milan Crha <mcrha redhat com>
Date: Wed Oct 4 09:47:40 2017 +0200
Initialize libxml2 global memory in the main()
There could happen crashes in libxml2 when being used for the first
time in multiple threads at once, like with xmlFindCharEncodingHandler()
function. This and some others require initialization in the main thread.
One example of such crash can be found in a downstream bug report:
https://bugzilla.redhat.com/show_bug.cgi?id=1380268
.../evolution-addressbook-factory-subprocess.c | 2 +
.../evolution-calendar-factory-subprocess.c | 2 +
src/libedataserver/e-xml-utils.c | 24 ++++++++++++++++++++
src/libedataserver/e-xml-utils.h | 2 +
.../evolution-addressbook-factory.c | 1 +
.../evolution-calendar-factory.c | 1 +
.../evolution-source-registry.c | 1 +
.../evolution-user-prompter.c | 1 +
8 files changed, 34 insertions(+), 0 deletions(-)
---
diff --git a/src/addressbook/libedata-book/evolution-addressbook-factory-subprocess.c
b/src/addressbook/libedata-book/evolution-addressbook-factory-subprocess.c
index 00a6b85..bea222f 100644
--- a/src/addressbook/libedata-book/evolution-addressbook-factory-subprocess.c
+++ b/src/addressbook/libedata-book/evolution-addressbook-factory-subprocess.c
@@ -184,6 +184,8 @@ main (gint argc,
exit (EXIT_FAILURE);
}
+ e_xml_initialize_in_main ();
+
loop = g_main_loop_new (NULL, FALSE);
manager = g_dbus_object_manager_server_new ("/org/gnome/evolution/dataserver/Subprocess/Backend");
diff --git a/src/calendar/libedata-cal/evolution-calendar-factory-subprocess.c
b/src/calendar/libedata-cal/evolution-calendar-factory-subprocess.c
index f131f39..1777964 100644
--- a/src/calendar/libedata-cal/evolution-calendar-factory-subprocess.c
+++ b/src/calendar/libedata-cal/evolution-calendar-factory-subprocess.c
@@ -184,6 +184,8 @@ main (gint argc,
exit (EXIT_FAILURE);
}
+ e_xml_initialize_in_main ();
+
loop = g_main_loop_new (NULL, FALSE);
manager = g_dbus_object_manager_server_new ("/org/gnome/evolution/dataserver/Subprocess/Backend");
diff --git a/src/libedataserver/e-xml-utils.c b/src/libedataserver/e-xml-utils.c
index c36b74b..d2e2c6b 100644
--- a/src/libedataserver/e-xml-utils.c
+++ b/src/libedataserver/e-xml-utils.c
@@ -27,6 +27,7 @@
#endif
#include <libxml/parser.h>
+#include <libxml/catalog.h>
#include <libxml/tree.h>
#include <libxml/xpathInternals.h>
@@ -39,6 +40,29 @@
#endif
/**
+ * e_xml_initialize_in_main: (skip)
+ *
+ * Initializes libxml library global memory. This should be called
+ * in the main thread. The function does nothing, when it had been
+ * called already.
+ *
+ * Since: 3.26.2
+ **/
+void
+e_xml_initialize_in_main (void)
+{
+ static volatile guint called = 0;
+
+ if (!g_atomic_int_or (&called, 1)) {
+ xmlInitMemory ();
+ xmlInitThreads ();
+ xmlInitGlobals ();
+ xmlInitializeCatalog ();
+ xmlInitParser ();
+ }
+}
+
+/**
* e_xml_parse_file: (skip)
* @filename: path to an XML file
*
diff --git a/src/libedataserver/e-xml-utils.h b/src/libedataserver/e-xml-utils.h
index 6707b6b..41bb70a 100644
--- a/src/libedataserver/e-xml-utils.h
+++ b/src/libedataserver/e-xml-utils.h
@@ -29,6 +29,8 @@
G_BEGIN_DECLS
+void e_xml_initialize_in_main (void);
+
xmlDoc * e_xml_parse_file (const gchar *filename);
gint e_xml_save_file (const gchar *filename,
xmlDoc *doc);
diff --git a/src/services/evolution-addressbook-factory/evolution-addressbook-factory.c
b/src/services/evolution-addressbook-factory/evolution-addressbook-factory.c
index b9e3fe5..4e8bb02 100644
--- a/src/services/evolution-addressbook-factory/evolution-addressbook-factory.c
+++ b/src/services/evolution-addressbook-factory/evolution-addressbook-factory.c
@@ -78,6 +78,7 @@ main (gint argc,
}
e_gdbus_templates_init_main_thread ();
+ e_xml_initialize_in_main ();
reload:
server = e_data_book_factory_new (NULL, &error);
diff --git a/src/services/evolution-calendar-factory/evolution-calendar-factory.c
b/src/services/evolution-calendar-factory/evolution-calendar-factory.c
index 6b76ff0..ee4ce1c 100644
--- a/src/services/evolution-calendar-factory/evolution-calendar-factory.c
+++ b/src/services/evolution-calendar-factory/evolution-calendar-factory.c
@@ -88,6 +88,7 @@ main (gint argc,
#endif
e_gdbus_templates_init_main_thread ();
+ e_xml_initialize_in_main ();
reload:
server = e_data_cal_factory_new (NULL, &error);
diff --git a/src/services/evolution-source-registry/evolution-source-registry.c
b/src/services/evolution-source-registry/evolution-source-registry.c
index 151e309..2dced10 100644
--- a/src/services/evolution-source-registry/evolution-source-registry.c
+++ b/src/services/evolution-source-registry/evolution-source-registry.c
@@ -176,6 +176,7 @@ main (gint argc,
}
e_gdbus_templates_init_main_thread ();
+ e_xml_initialize_in_main ();
reload:
diff --git a/src/services/evolution-user-prompter/evolution-user-prompter.c
b/src/services/evolution-user-prompter/evolution-user-prompter.c
index 3f37163..8dc7c26 100644
--- a/src/services/evolution-user-prompter/evolution-user-prompter.c
+++ b/src/services/evolution-user-prompter/evolution-user-prompter.c
@@ -67,6 +67,7 @@ main (gint argc,
}
e_gdbus_templates_init_main_thread ();
+ e_xml_initialize_in_main ();
reload:
server = e_user_prompter_server_new ();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]