From 5d5978037ee924d5e210b1ca6650804b110a66d7 Mon Sep 17 00:00:00 2001 From: Akihito Koriyama Date: Tue, 5 Nov 2024 17:59:55 +0900 Subject: [PATCH] Refactor error handling in intercept hash update function Previously, on error, the function manually released class and method names, destroyed the handler, and freed the info structure. This commit centralizes cleanup logic by using `php_rayaop_free_intercept_info()` for better maintainability and clarity. --- rayaop.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/rayaop.c b/rayaop.c index 71b9df2..d1e5cfd 100644 --- a/rayaop.c +++ b/rayaop.c @@ -126,10 +126,10 @@ PHP_RAYAOP_API php_rayaop_intercept_info *php_rayaop_find_intercept_info(const c } /* Parameter preparation and cleanup */ -static void prepare_intercept_params(zend_execute_data *execute_data, zval *params, php_rayaop_intercept_info *info) { +static bool prepare_intercept_params(zend_execute_data *execute_data, zval *params, php_rayaop_intercept_info *info) { if (!execute_data->This.value.obj) { php_rayaop_handle_error(RAYAOP_E_INVALID_HANDLER, "Object instance is NULL"); - return; + return false; } ZVAL_OBJ(¶ms[0], execute_data->This.value.obj); @@ -147,6 +147,7 @@ static void prepare_intercept_params(zend_execute_data *execute_data, zval *para } } } + return true; } static void cleanup_intercept_params(zval *params) { @@ -201,6 +202,17 @@ static void rayaop_execute_ex(zend_execute_data *execute_data) { zval params[3]; prepare_intercept_params(execute_data, params, info); + if (!prepare_intercept_params(execute_data, params, info)) { + RAYAOP_G(is_intercepting) = 0; + if (php_rayaop_original_execute_ex) { + php_rayaop_original_execute_ex(execute_data); + } else { + zend_execute_ex(execute_data); + } + efree(key); + RAYAOP_G(execution_depth)--; + return; + } RAYAOP_G(is_intercepting) = 1; ZVAL_UNDEF(&retval);