Skip to content

Commit

Permalink
Refactor error handling in intercept hash update function
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
koriym committed Nov 5, 2024
1 parent 83dcd9b commit 5d59780
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions rayaop.c
Original file line number Diff line number Diff line change
Expand Up @@ -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(&params[0], execute_data->This.value.obj);
Expand All @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 5d59780

Please sign in to comment.