fix #1: Segfault on PHP 7.4 with empty array
[m6w6/ext-json_post] / php_json_post.c
index d9b72957726301f2eaf256fa75699a711570b149..c2e5ba69eabb4618b45c5c541a451472d351c959 100644 (file)
@@ -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;