[gdome] Fix thread issues
- From: Gustavo Sverzut Barbieri <Gustavo Barbieri indt org br>
- To: gdome gnome org
- Cc: eduardo lima indt org br, eduardo rocha indt org br, renato chencarek indt org br
- Subject: [gdome] Fix thread issues
- Date: Thu, 18 May 2006 15:18:40 -0300
While developing a Gdome application using threads, I found an issue with the
way it handles singletons, like dome-xml-domimpl.c and gdome-xpath-xpeval.c.
You first test if global instance is NULL, if not you allocate the new,
_EMPTY_ instance directly to the global instance, then goes to fill needed
fields, like "vtab".
Problem happens if you allocate and is preempted by system. Global pointer is
not NULL anymore, however you don't have any required field, like "vtab", and
can segfault your application.
This could be solved easily without any locks, just use a local variable while
the instance is not setup, just then make it global.
Attached patch fix this problem.
Thanks,
--
Gustavo Sverzut Barbieri
------------------------
INdT, Recife, Brazil
Jabber: barbieri gmail com
MSN: barbieri gmail com
ICQ#: 17249123
Skype: gsbarbieri
Mobile: +55 (81) 9927 0010
Phone: +1 (347) 624 6296; 08122692 sip stanaphone com
GPG: 0xB640E1A2 @ wwwkeys.pgp.net
diff -ur gdome2-fix/libgdome/gdomecore/gdome-xml-domimpl.c gdome2-orig/libgdome/gdomecore/gdome-xml-domimpl.c
--- gdome2-fix/libgdome/gdomecore/gdome-xml-domimpl.c 2006-05-18 15:02:22.000000000 -0300
+++ gdome2-orig/libgdome/gdomecore/gdome-xml-domimpl.c 2005-05-13 04:05:56.000000000 -0300
@@ -70,11 +70,10 @@
GdomeDOMImplementation *
gdome_xml_di_mkref (void) {
if (gdome_xml_DOMImplementation == NULL) {
- Gdome_xml_DOMImplementation *n;
- n = g_new0 (Gdome_xml_DOMImplementation, 1);
- n->refcnt = 1;
- n->vtab = &gdome_xml_di_vtab;
- gdome_xml_DOMImplementation = n;
+ gdome_xml_DOMImplementation = g_new (Gdome_xml_DOMImplementation, 1);
+ memset(gdome_xml_DOMImplementation, 0, sizeof(Gdome_xml_DOMImplementation));
+ gdome_xml_DOMImplementation->refcnt = 1;
+ gdome_xml_DOMImplementation->vtab = &gdome_xml_di_vtab;
} else
gdome_xml_DOMImplementation->refcnt++;
diff -ur gdome2-fix/libgdome/xpath/gdome-xpath-xpeval.c gdome2-orig/libgdome/xpath/gdome-xpath-xpeval.c
--- gdome2-fix/libgdome/xpath/gdome-xpath-xpeval.c 2006-05-18 15:01:55.000000000 -0300
+++ gdome2-orig/libgdome/xpath/gdome-xpath-xpeval.c 2006-05-18 15:11:48.000000000 -0300
@@ -53,11 +53,9 @@
gdome_xpath_xpeval_mkref (void)
{
if (gdome_xpath_XPathEvaluator == NULL) {
- Gdome_xpath_XPathEvaluator *n;
- n = g_new0 (Gdome_xpath_XPathEvaluator, 1);
- n->refcnt = 1;
- n->vtab = &gdome_xpath_xpeval_vtab;
- gdome_xpath_XPathEvaluator = n;
+ gdome_xpath_XPathEvaluator = g_new (Gdome_xpath_XPathEvaluator, 1);
+ gdome_xpath_XPathEvaluator->refcnt = 1;
+ gdome_xpath_XPathEvaluator->vtab = &gdome_xpath_xpeval_vtab;
} else
gdome_xpath_XPathEvaluator->refcnt++;
[Date Prev][
Date Next] [Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]