Index: /trunk/utils.c
===================================================================
--- /trunk/utils.c	(revision 902)
+++ /trunk/utils.c	(revision 903)
@@ -27,4 +27,14 @@
 	} while(0)
 #endif
+
+static void (*old_zend_error_cb)(int type, const char *error_filename, const uint error_lineno, const char *format, va_list args) = NULL;
+static void call_old_zend_error_cb(int type, const char *error_filename, const uint error_lineno, const char *format, ...) /* {{{ */
+{
+	va_list args;
+	va_start(args, format);
+	old_zend_error_cb(type, error_filename, error_lineno, format, args);
+}
+/* }}} */
+
 xc_compile_result_t *xc_compile_result_init(xc_compile_result_t *cr, /* {{{ */
 		zend_op_array *op_array,
@@ -587,5 +597,9 @@
 
 	sandbox = (xc_sandbox_t *) XG(sandbox);
-	assert(sandbox != NULL);
+	if (!sandbox) {
+		old_zend_error_cb(type, error_filename, error_lineno, format, args);
+		return;
+	}
+
 	switch (type) {
 #ifdef E_STRICT
@@ -614,16 +628,21 @@
 		/* give up, and user handler is not supported in this case */
 		zend_uint i;
-		zend_uint orig_lineno = CG(zend_lineno);
-		zend_error_cb = sandbox->orig_zend_error_cb;
+		zend_uint old_lineno = CG(zend_lineno);
 
 		for (i = 0; i < sandbox->compilererror_cnt; i ++) {
 			compilererror = &sandbox->compilererrors[i];
 			CG(zend_lineno) = compilererror->lineno;
-			zend_error(compilererror->type, "%s", compilererror->error);
-		}
-		CG(zend_lineno) = orig_lineno;
-		sandbox->compilererror_cnt = 0;
-
-		sandbox->orig_zend_error_cb(type, error_filename, error_lineno, format, args);
+			call_old_zend_error_cb(compilererror->type, error_filename, error_lineno, "%s", compilererror->error);
+			efree(compilererror->error);
+		}
+		if (sandbox->compilererrors) {
+			efree(sandbox->compilererrors);
+			sandbox->compilererrors = NULL;
+		}
+		sandbox->compilererror_cnt  = 0;
+		sandbox->compilererror_size = 0;
+
+		CG(zend_lineno) = old_lineno;
+		old_zend_error_cb(type, error_filename, error_lineno, format, args);
 		break;
 	}
@@ -791,6 +810,4 @@
 	sandbox->compilererror_cnt  = 0;
 	sandbox->compilererror_size = 0;
-	sandbox->orig_zend_error_cb = zend_error_cb;
-	zend_error_cb = xc_sandbox_error_cb;
 #endif
 
@@ -892,5 +909,4 @@
 #ifdef XCACHE_ERROR_CACHING
 	EG(user_error_handler_error_reporting) = sandbox->orig_user_error_handler_error_reporting;
-	zend_error_cb = sandbox->orig_zend_error_cb;
 #endif
 
@@ -1016,2 +1032,24 @@
 
 #endif
+
+/* init/destroy */
+int xc_util_init(int module_number TSRMLS_DC) /* {{{ */
+{
+#ifdef XCACHE_ERROR_CACHING
+	old_zend_error_cb = zend_error_cb;
+	zend_error_cb = xc_sandbox_error_cb;
+#endif
+
+	return SUCCESS;
+}
+/* }}} */
+void xc_util_destroy() /* {{{ */
+{
+#ifdef XCACHE_ERROR_CACHING
+	if (zend_error_cb == xc_sandbox_error_cb) {
+		zend_error_cb = old_zend_error_cb;
+	}
+#endif
+}
+/* }}} */
+
Index: /trunk/utils.h
===================================================================
--- /trunk/utils.h	(revision 902)
+++ /trunk/utils.h	(revision 903)
@@ -40,4 +40,7 @@
 #endif /* XCACHE_DEBUG */
 #include <assert.h>
+
+int xc_util_init(int module_number TSRMLS_DC);
+void xc_util_destroy();
 
 typedef struct {
@@ -104,5 +107,4 @@
 #ifdef XCACHE_ERROR_CACHING
 	int orig_user_error_handler_error_reporting;
-	void (*orig_zend_error_cb)(int type, const char *error_filename, const uint error_lineno, const char *format, va_list args);
 	zend_uint compilererror_cnt;
 	zend_uint compilererror_size;
Index: /trunk/xcache.c
===================================================================
--- /trunk/xcache.c	(revision 902)
+++ /trunk/xcache.c	(revision 903)
@@ -3735,4 +3735,5 @@
 	}
 
+	xc_util_init(module_number TSRMLS_CC);
 #ifdef HAVE_XCACHE_COVERAGER
 	xc_coverager_init(module_number TSRMLS_CC);
@@ -3763,4 +3764,5 @@
 	xc_coverager_destroy();
 #endif
+	xc_util_destroy();
 
 	if (xc_coredump_dir && xc_coredump_dir[0]) {
