diff --git a/CHANGELOG b/CHANGELOG
index c208b31..a2a782d 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -25,6 +25,7 @@
 - check for "*" when looking up wildcard in LDAP.
 - fix LDAP schema discovery.
 - add SEARCH_BASE configuration option.
+- work around segv at exit due to libxml2 tsd usage.
 
 18/06/2007 autofs-5.0.2
 -----------------------
diff --git a/aclocal.m4 b/aclocal.m4
index d0d8346..ffeb232 100644
--- a/aclocal.m4
+++ b/aclocal.m4
@@ -167,6 +167,19 @@ else
   HAVE_LIBXML=1
   XML_LIBS=`$XML_CONFIG --libs`
   XML_FLAGS=`$XML_CONFIG --cflags`
+  XML_VER=`$XML_CONFIG --version`
+  XML_MAJOR=`echo $XML_VER|cut -d\. -f1`
+  if test $XML_MAJOR -le 2
+  then
+    XML_MINOR=`echo $XML_VER|cut -d\. -f2`
+    if test $XML_MINOR -le 6
+    then
+      XML_REV=`echo $XML_VER|cut -d\. -f3`
+      if test $XML_REV -le 99; then
+        AC_DEFINE(LIBXML2_WORKAROUND,1, [Use libxml2 tsd usage workaround])
+      fi
+    fi
+  fi
 fi])
 
 dnl --------------------------------------------------------------------------
diff --git a/configure b/configure
index b723d74..3508224 100755
--- a/configure
+++ b/configure
@@ -2498,6 +2498,23 @@ echo "${ECHO_T}yes" >&6; }
   HAVE_LIBXML=1
   XML_LIBS=`$XML_CONFIG --libs`
   XML_FLAGS=`$XML_CONFIG --cflags`
+  XML_VER=`$XML_CONFIG --version`
+  XML_MAJOR=`echo $XML_VER|cut -d\. -f1`
+  if test $XML_MAJOR -le 2
+  then
+    XML_MINOR=`echo $XML_VER|cut -d\. -f2`
+    if test $XML_MINOR -le 6
+    then
+      XML_REV=`echo $XML_VER|cut -d\. -f3`
+      if test $XML_REV -le 99; then
+
+cat >>confdefs.h <<\_ACEOF
+#define LIBXML2_WORKAROUND 1
+_ACEOF
+
+      fi
+    fi
+  fi
 fi
 
 #
diff --git a/daemon/automount.c b/daemon/automount.c
index 4b6584a..aeeb7cb 100644
--- a/daemon/automount.c
+++ b/daemon/automount.c
@@ -40,6 +40,9 @@
 #include <sys/utsname.h>
 
 #include "automount.h"
+#ifdef LIBXML2_WORKAROUND
+#include <dlfcn.h>
+#endif
 
 const char *program;		/* Initialized with argv[0] */
 const char *version = VERSION_STRING;	/* Program version */
@@ -1681,6 +1684,11 @@ int main(int argc, char *argv[])
 		close(start_pipefd[1]);
 		exit(1);
 	}
+
+#ifdef LIBXML2_WORKAROUND
+	void *dh = dlopen("libxml2.so", RTLD_NOW);
+#endif
+
 	if (!master_read_master(master_list, age, 0)) {
 		master_kill(master_list);
 		*pst_stat = 3;
@@ -1702,5 +1710,9 @@ int main(int argc, char *argv[])
 	}
 	closelog();
 
+#ifdef LIBXML2_WORKAROUND
+	if (dh)
+		dlclose(dh);
+#endif
 	exit(0);
 }
diff --git a/include/config.h.in b/include/config.h.in
index 942694c..9669872 100644
--- a/include/config.h.in
+++ b/include/config.h.in
@@ -60,6 +60,9 @@
 /* Define to 1 if you have the <unistd.h> header file. */
 #undef HAVE_UNISTD_H
 
+/* Use libxml2 tsd usage workaround */
+#undef LIBXML2_WORKAROUND
+
 /* Define to the address where bug reports for this package should be sent. */
 #undef PACKAGE_BUGREPORT
 
diff --git a/modules/lookup_ldap.c b/modules/lookup_ldap.c
index da52e71..49a9a9b 100644
--- a/modules/lookup_ldap.c
+++ b/modules/lookup_ldap.c
@@ -1998,9 +1998,6 @@ int lookup_done(void *context)
 	struct lookup_context *ctxt = (struct lookup_context *) context;
 	int rv = close_parse(ctxt->parse);
 #ifdef WITH_SASL
-	EVP_cleanup();
-	ERR_free_strings();
-
 	autofs_sasl_done(ctxt);
 #endif
 	free_context(ctxt);
