From 2c0763aeb494fcaf9cb3e0a47688e537fe81d579 Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Thu, 10 Jun 2010 11:45:51 +0000 Subject: [PATCH] Fixed bug #51822i (Segfault with strange __destruct() for static class variables) --- NEWS | 2 ++ Zend/tests/bug51822.phpt | 40 ++++++++++++++++++++++++++++++++++++++++ Zend/zend_opcode.c | 5 ++++- 3 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 Zend/tests/bug51822.phpt diff --git a/NEWS b/NEWS index c8d1ff5fcd..0455f6037f 100644 --- a/NEWS +++ b/NEWS @@ -22,6 +22,8 @@ PHP NEWS - Fixed bug #51905 (ReflectionParameter fails if default value is an array with an access to self::). (Felipe) constant array). (Felipe) +- Fixed bug #51822i (Segfault with strange __destruct() for static class + variables). (Dmitry) - Fixed bug #51671 (imagefill does not work correctly for small images). (Pierre) - Fixed bug #51670 (getColumnMeta causes segfault when re-executing query diff --git a/Zend/tests/bug51822.phpt b/Zend/tests/bug51822.phpt new file mode 100644 index 0000000000..cffae7bb1a --- /dev/null +++ b/Zend/tests/bug51822.phpt @@ -0,0 +1,40 @@ +--TEST-- +Bug #51822 (Segfault with strange __destruct() for static class variables) +--FILE-- +test = new DestructableObject; + echo "1\n"; + } +} + +class Test +{ + public static $mystatic; +} + +// Uncomment this to avoid segfault +//Test::$mystatic = new DestructorCreator(); + +$x = new Test(); + +if (!isset(Test::$mystatic)) + Test::$mystatic = new DestructorCreator(); + +echo "bla\n"; +?> +--EXPECT-- +bla +1 +2 diff --git a/Zend/zend_opcode.c b/Zend/zend_opcode.c index 7139af3f66..e10d819974 100644 --- a/Zend/zend_opcode.c +++ b/Zend/zend_opcode.c @@ -157,7 +157,10 @@ ZEND_API int zend_cleanup_class_data(zend_class_entry **pce TSRMLS_DC) /* Note that only run-time accessed data need to be cleaned up, pre-defined data can not contain objects and thus are not probelmatic */ zend_hash_apply(&(*pce)->function_table, (apply_func_t) zend_cleanup_function_data_full TSRMLS_CC); - (*pce)->static_members = NULL; + if ((*pce)->static_members) { + zend_hash_clean((*pce)->static_members); + (*pce)->static_members = NULL; + } } else if (CE_STATIC_MEMBERS(*pce)) { zend_hash_destroy(CE_STATIC_MEMBERS(*pce)); FREE_HASHTABLE(CE_STATIC_MEMBERS(*pce)); -- 2.40.0