com php-src: Fixed startup segfault in non-debug builds Fixes issue #87: sapi/phpdbg/phpdbg.c
| From: | Bob Weinand | Date: | Tue, 03 Jun 2014 21:24:55 +0000 |
| Subject: | com php-src: Fixed startup segfault in non-debug builds Fixes issue #87: sapi/phpdbg/phpdbg.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-78680@lists.php.net to get a copy of this message | ||
Commit: a1b0ae4247b22244a4dd25a053d8fa61d85a77dd
Author: Bob Weinand <bobwei9@hotmail.com> Tue, 3 Jun 2014 21:00:45 +0000
Parents: 241211975e19dbf5b979d208807c7d178aca79fc
Branches: master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=a1b0ae4247b22244a4dd25a053d8fa61d85a77dd
Log:
Fixed startup segfault in non-debug builds
Fixes issue #87
Bugs:
https://bugs.php.net/87
Changed paths:
M sapi/phpdbg/phpdbg.c
Diff:
diff --git a/sapi/phpdbg/phpdbg.c b/sapi/phpdbg/phpdbg.c
index fc12183..0239e69 100644
--- a/sapi/phpdbg/phpdbg.c
+++ b/sapi/phpdbg/phpdbg.c
@@ -879,6 +879,32 @@ void phpdbg_signal_handler(int sig, siginfo_t *info, void *context) {
}
#endif
+static inline zend_mm_heap *phpdbg_mm_get_heap() {
+ zend_mm_heap *mm_heap;
+
+ TSRMLS_FETCH();
+
+ mm_heap = zend_mm_set_heap(NULL TSRMLS_CC);
+ zend_mm_set_heap(mm_heap TSRMLS_CC);
+
+ return mm_heap;
+}
+
+void *phpdbg_malloc_wrapper(size_t size)
+{
+ return zend_mm_alloc(phpdbg_mm_get_heap(), size);
+}
+
+void phpdbg_free_wrapper(void *p)
+{
+ zend_mm_free(phpdbg_mm_get_heap(), p);
+}
+
+void *phpdbg_realloc_wrapper(void *ptr, size_t size)
+{
+ return zend_mm_realloc(phpdbg_mm_get_heap(), ptr, size);
+}
+
int main(int argc, char **argv) /* {{{ */
{
sapi_module_struct *phpdbg = &phpdbg_sapi_module;
@@ -1221,20 +1247,17 @@ phpdbg_main:
EXCEPTION_POINTERS *xp;
__try {
#endif
- zend_mm_heap *mm_heap = zend_mm_set_heap(NULL TSRMLS_CC);
-#if ZEND_DEBUG
- if (!mm_heap->use_zend_alloc) {
- mm_heap->_malloc = malloc;
- mm_heap->_realloc = realloc;
- mm_heap->_free = free;
-#endif
- PHPDBG_G(original_free_function) = mm_heap->_free;
- mm_heap->_free = phpdbg_watch_efree;
+ zend_mm_heap *mm_heap = phpdbg_mm_get_heap();
+
+ if (mm_heap->use_zend_alloc) {
+ mm_heap->_malloc = phpdbg_malloc_wrapper;
+ mm_heap->_realloc = phpdbg_realloc_wrapper;
+ mm_heap->_free = phpdbg_free_wrapper;
mm_heap->use_zend_alloc = 0;
-#if ZEND_DEBUG
}
-#endif
- zend_mm_set_heap(mm_heap TSRMLS_CC);
+
+ PHPDBG_G(original_free_function) = mm_heap->_free;
+ mm_heap->_free = phpdbg_watch_efree;
zend_activate(TSRMLS_C);