[svn:PHP-Sandwich] rev 989 - PHP-Sandwich/trunk
[email protected] 15 Apr 2005 15:03:28 -0000
| Newsgroups | perl.php.sandwich.dev |
|---|---|
| Message-ID | <[email protected]> |
Author: wez
Date: Fri Apr 15 08:03:27 2005
New Revision: 989
Modified:
PHP-Sandwich/trunk/PHP.xs
PHP-Sandwich/trunk/phpinterp.c
PHP-Sandwich/trunk/phpinterp.h
Log:
need to bracket the emalloc() and zval_dtor calls with the correct interpreter,
otherwise the memory will be allocated on the wrong context.
This would lead to a memory leak in the best case, and a crash in the worst
case, when zvals are freed from the wrong context.
Now we're safe.
Modified: PHP-Sandwich/trunk/PHP.xs
==============================================================================
--- PHP-Sandwich/trunk/PHP.xs (original)
+++ PHP-Sandwich/trunk/PHP.xs Fri Apr 15 08:03:27 2005
@@ -240,6 +240,10 @@
int i;
int param_count = 0;
zval *retval;
+ void *old_ctx;
+
+ old_ctx = tsrm_set_interpreter_context(interp->ctx);
+
INIT_ZVAL(method);
ZVAL_STRING(&method, method_name, 1);
if(items > 2) {
@@ -282,6 +286,8 @@
}
}
zval_dtor(&method);
+
+ tsrm_set_interpreter_context(old_ctx);
}
OUTPUT:
RETVAL
Modified: PHP-Sandwich/trunk/phpinterp.c
==============================================================================
--- PHP-Sandwich/trunk/phpinterp.c (original)
+++ PHP-Sandwich/trunk/phpinterp.c Fri Apr 15 08:03:27 2005
@@ -196,26 +196,19 @@
zval *sandwich_call_function(sandwich_per_interp *interp, zval *method, zval **params, zend_uint param_count)
{
- void *old_ctx = NULL;
- old_ctx = tsrm_set_interpreter_context(interp->ctx);
- {
- TSRMLS_FETCH();
- zend_try {
- zval *retval;
- MAKE_STD_ZVAL(retval);
- if(call_user_function(EG(function_table), NULL, method, retval, param_count, params TSRMLS_CC) == FAILURE) {
- return NULL;
- }
- return retval;
- } zend_catch {
- Perl_croak("Failed to eval your PHP code\n");
- goto cleanup;
- } zend_end_try() {
+ TSRMLS_FETCH();
+ zend_try {
+ zval *retval;
+ MAKE_STD_ZVAL(retval);
+ if(call_user_function(EG(function_table), NULL, method, retval, param_count, params TSRMLS_CC) == FAILURE) {
+ return NULL;
}
+ return retval;
+ } zend_catch {
+ Perl_croak("Failed to eval your PHP code\n");
+ } zend_end_try() {
+ return NULL;
}
-cleanup:
- tsrm_set_interpreter_context(old_ctx);
- return;
}
/* vim: set ts=2 sts=2 ai bs=2 expandtab : */
Modified: PHP-Sandwich/trunk/phpinterp.h
==============================================================================
--- PHP-Sandwich/trunk/phpinterp.h (original)
+++ PHP-Sandwich/trunk/phpinterp.h Fri Apr 15 08:03:27 2005
@@ -24,6 +24,8 @@
void sandwich_eval(sandwich_per_interp *interp, char *code);
void sandwich_include(sandwich_per_interp *interp, char *file);
+
+/* NOTE: caller must tsrm_set_interpreter_context and reset the old one */
zval *sandwich_call_function(sandwich_per_interp *interp, zval *method, zval **params, zend_uint param_count);