diff -Naur a/libxml2-2.9.1/parser.c b/libxml2-2.9.1/parser.c
--- a/libxml2-2.9.1/parser.c	2013-04-16 19:09:18.000000000 +0530
+++ b/libxml2-2.9.1/parser.c	2013-07-15 19:11:10.000000000 +0530
@@ -83,6 +83,9 @@
 #ifdef HAVE_LZMA_H
 #include <lzma.h>
 #endif
+#ifdef LIBXML_THREAD_ENABLED
+#include<pthread.h>
+#endif
 
 #include "buf.h"
 #include "enc.h"
@@ -14677,7 +14680,12 @@
 #endif
 
 extern void XMLCDECL xmlGenericErrorDefaultFunc(void *ctx, const char *msg, ...);
+#ifdef LIBXML_THREAD_ENABLED
+pthread_mutex_t xmlRefMutex = PTHREAD_MUTEX_INITIALIZER;
+static int xmlRefCount = 0;
+#else
 static int xmlParserInitialized = 0;
+#endif
 
 /**
  * xmlInitParser:
@@ -14689,12 +14697,16 @@
 
 void
 xmlInitParser(void) {
-    if (xmlParserInitialized != 0)
-	return;
-
 #ifdef LIBXML_THREAD_ENABLED
+    pthread_mutex_lock(&xmlRefMutex);
+    if(xmlRefCount++ != 0){
+        pthread_mutex_unlock(&xmlRefMutex);
+        return;
+    }
     __xmlGlobalInitMutexLock();
-    if (xmlParserInitialized == 0) {
+#else
+    if (xmlParserInitialized != 0)
+	return;
 #endif
 	xmlInitThreads();
 	xmlInitGlobals();
@@ -14716,10 +14728,11 @@
 #ifdef LIBXML_XPATH_ENABLED
 	xmlXPathInit();
 #endif
-	xmlParserInitialized = 1;
 #ifdef LIBXML_THREAD_ENABLED
-    }
     __xmlGlobalInitMutexUnlock();
+    pthread_mutex_unlock(&xmlRefMutex);
+#else
+    xmlParserInitialized = 1;
 #endif
 }
 
@@ -14747,8 +14760,14 @@
 
 void
 xmlCleanupParser(void) {
+#ifdef LIBXML_THREAD_ENABLED
+    pthread_mutex_lock(&xmlRefMutex);
+    if(xmlRefCount == 1)
+    {
+#else
     if (!xmlParserInitialized)
 	return;
+#endif
 
     xmlCleanupCharEncodingHandlers();
 #ifdef LIBXML_CATALOG_ENABLED
@@ -14767,7 +14786,18 @@
     xmlResetLastError();
     xmlCleanupThreads(); /* must be last if called not from the main thread */
     xmlCleanupMemory();
+#ifdef LIBXML_THREAD_ENABLED
+        xmlRefCount = 0;
+    }
+    else
+    {
+        if(xmlRefCount)
+            xmlRefCount--;
+    }
+    pthread_mutex_unlock(&xmlRefMutex);
+#else
     xmlParserInitialized = 0;
+#endif
 }
 
 /************************************************************************
