d2399a
From 3c87945c95c9c31986e690bb046c70e58c8d8896 Mon Sep 17 00:00:00 2001
d2399a
From: Xinchen Hui <laruence@php.net>
d2399a
Date: Wed, 5 Jun 2013 17:25:00 +0800
d2399a
Subject: [PATCH] Fixed bug #64960 (Segfault in gc_zval_possible_root)
d2399a
d2399a
---
d2399a
 NEWS                     |  2 ++
d2399a
 Zend/tests/bug64960.phpt | 40 ++++++++++++++++++++++++++++++++++++++++
d2399a
 Zend/zend_execute_API.c  |  6 ++----
d2399a
 3 files changed, 44 insertions(+), 4 deletions(-)
d2399a
 create mode 100644 Zend/tests/bug64960.phpt
d2399a
d2399a
diff --git a/Zend/tests/bug64960.phpt b/Zend/tests/bug64960.phpt
d2399a
new file mode 100644
d2399a
index 0000000..b31cca3
d2399a
--- /dev/null
d2399a
+++ b/Zend/tests/bug64960.phpt
d2399a
@@ -0,0 +1,40 @@
d2399a
+--TEST--
d2399a
+Bug #64960 (Segfault in gc_zval_possible_root)
d2399a
+--FILE--
d2399a
+
d2399a
+// this makes ob_end_clean raise an error
d2399a
+ob_end_flush();
d2399a
+
d2399a
+class ExceptionHandler {
d2399a
+	public function __invoke (Exception $e)
d2399a
+	{
d2399a
+		// this triggers the custom error handler
d2399a
+		ob_end_clean();
d2399a
+	}
d2399a
+}
d2399a
+
d2399a
+// this must be a class, closure does not trigger segfault
d2399a
+set_exception_handler(new ExceptionHandler());
d2399a
+
d2399a
+// exception must be throwed from error handler.
d2399a
+set_error_handler(function()
d2399a
+{
d2399a
+	$e = new Exception;
d2399a
+	$e->_trace = debug_backtrace();
d2399a
+	
d2399a
+	throw $e;
d2399a
+});
d2399a
+
d2399a
+// trigger error handler
d2399a
+$a['waa'];
d2399a
+?>
d2399a
+--EXPECTF--
d2399a
+Notice: ob_end_flush(): failed to delete and flush buffer. No buffer to delete or flush in %sbug64960.php on line 3
d2399a
+
d2399a
+Fatal error: Uncaught exception 'Exception' in %sbug64960.php:19
d2399a
+Stack trace:
d2399a
+#0 [internal function]: {closure}(8, 'ob_end_clean():...', '%s', 9, Array)
d2399a
+#1 %sbug64960.php(9): ob_end_clean()
d2399a
+#2 [internal function]: ExceptionHandler->__invoke(Object(Exception))
d2399a
+#3 {main}
d2399a
+  thrown in %sbug64960.php on line 19
d2399a
diff --git a/Zend/zend_execute_API.c b/Zend/zend_execute_API.c
d2399a
index 9781889..687520d 100644
d2399a
--- a/Zend/zend_execute_API.c
d2399a
+++ b/Zend/zend_execute_API.c
d2399a
@@ -263,15 +263,13 @@ void shutdown_executor(TSRMLS_D) /* {{{ */
d2399a
 		if (EG(user_error_handler)) {
d2399a
 			zeh = EG(user_error_handler);
d2399a
 			EG(user_error_handler) = NULL;
d2399a
-			zval_dtor(zeh);
d2399a
-			FREE_ZVAL(zeh);
d2399a
+			zval_ptr_dtor(&zeh;;
d2399a
 		}
d2399a
 
d2399a
 		if (EG(user_exception_handler)) {
d2399a
 			zeh = EG(user_exception_handler);
d2399a
 			EG(user_exception_handler) = NULL;
d2399a
-			zval_dtor(zeh);
d2399a
-			FREE_ZVAL(zeh);
d2399a
+			zval_ptr_dtor(&zeh;;
d2399a
 		}
d2399a
 
d2399a
 		zend_stack_destroy(&EG(user_error_handlers_error_reporting));
d2399a
-- 
d2399a
1.7.11.5
d2399a