From: Michael Wallner Date: Wed, 13 May 2020 12:25:56 +0000 (+0200) Subject: fix #1: Segfault on PHP 7.4 with empty array X-Git-Tag: v1.0.2~2 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=88d61717dea2609ba0f358c87c0d540cfc3ec10a;p=m6w6%2Fext-json_post fix #1: Segfault on PHP 7.4 with empty array closes #2 --- diff --git a/php_json_post.c b/php_json_post.c index d9b7295..c2e5ba6 100644 --- a/php_json_post.c +++ b/php_json_post.c @@ -68,8 +68,13 @@ static SAPI_POST_HANDLER_FUNC(php_json_post_handler) switch (Z_TYPE(tmp)) { case IS_OBJECT: case IS_ARRAY: - zval_dtor(arg); - ZVAL_COPY_VALUE(&PG(http_globals)[TRACK_VARS_POST], &tmp); + if (zend_hash_num_elements(HASH_OF(&tmp))) { + zval_dtor(arg); + ZVAL_COPY_VALUE(&PG(http_globals)[TRACK_VARS_POST], &tmp); + } else { + /* PHP-7.4 optimizes empty array */ + zval_ptr_dtor(&tmp); + } break; default: break;