From 3238f21a857c27c6690f7d3b6a1e4ac4ecadd160 Mon Sep 17 00:00:00 2001 From: NathanFreeman <1056159381@qq.com> Date: Sat, 26 Aug 2023 21:22:10 +0800 Subject: [PATCH] Fix memoty leak --- ext-src/php_swoole_cxx.h | 2 +- ext-src/php_swoole_http_server.h | 4 ++++ ext-src/swoole_http_server.cc | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/ext-src/php_swoole_cxx.h b/ext-src/php_swoole_cxx.h index 10a80371523..46fd2d61545 100644 --- a/ext-src/php_swoole_cxx.h +++ b/ext-src/php_swoole_cxx.h @@ -516,7 +516,7 @@ class Variable { } ~Variable() { - del_ref(); + zval_ptr_dtor(&value); } }; diff --git a/ext-src/php_swoole_http_server.h b/ext-src/php_swoole_http_server.h index e55bc3c3e0e..bd9da7179e6 100644 --- a/ext-src/php_swoole_http_server.h +++ b/ext-src/php_swoole_http_server.h @@ -74,6 +74,10 @@ static inline void http_server_add_server_array(HashTable *ht, zend_string *key, zend_hash_add(ht, key, &tmp); } +static inline void http_server_add_server_array(HashTable *ht, zend_string *key, zval *value) { + zend_hash_add(ht, key, value); +} + static inline void http_server_set_object_fd_property(zend_object *object, zend_class_entry *ce, long fd) { zval *zv = zend_hash_find(&ce->properties_info, SW_ZSTR_KNOWN(SW_ZEND_STR_FD)); zend_property_info *property_info = (zend_property_info *) Z_PTR_P(zv); diff --git a/ext-src/swoole_http_server.cc b/ext-src/swoole_http_server.cc index 48d331fff93..2f68abaee9c 100644 --- a/ext-src/swoole_http_server.cc +++ b/ext-src/swoole_http_server.cc @@ -128,7 +128,7 @@ int php_swoole_http_server_onReceive(Server *serv, RecvData *req) { iter = rs.first; } iter->second.add_ref(); - zend_hash_add(ht, SW_ZSTR_KNOWN(SW_ZEND_STR_REMOTE_ADDR), iter->second.ptr()); + http_server_add_server_array(ht, SW_ZSTR_KNOWN(SW_ZEND_STR_REMOTE_ADDR), iter->second.ptr()); } else { http_server_add_server_array(ht, SW_ZSTR_KNOWN(SW_ZEND_STR_REMOTE_ADDR), conn->info.get_ip()); }