FAQ

[svn:PHP-Sandwich] r1490 - PHP-Sandwich/trunk

Gschlossnagle
Aug 29, 2005 at 9:43 pm
Author: gschlossnagle
Date: Mon Aug 29 14:43:21 2005
New Revision: 1490

Modified:
PHP-Sandwich/trunk/PHP.xs
PHP-Sandwich/trunk/phpinterp.c
Log:
Combat memory leakage:

Fix refcount on interpreters
Implement pooled refcount re-usage.



Modified: PHP-Sandwich/trunk/PHP.xs
==============================================================================
--- PHP-Sandwich/trunk/PHP.xs (original)
+++ PHP-Sandwich/trunk/PHP.xs Mon Aug 29 14:43:21 2005
@@ -521,7 +521,6 @@ SV* SAND_new(classname, ...)
}
RETVAL = newSV(0);
sv_setref_pv(RETVAL, classname, (void *)interp);
- SvREFCNT_inc(RETVAL);
}
OUTPUT:
RETVAL

Modified: PHP-Sandwich/trunk/phpinterp.c
==============================================================================
--- PHP-Sandwich/trunk/phpinterp.c (original)
+++ PHP-Sandwich/trunk/phpinterp.c Mon Aug 29 14:43:21 2005
@@ -18,6 +18,13 @@
static sandwich_per_interp *one_true_interp = NULL;
#endif

+struct interp_list {
+ void *interp;
+ struct interp_list *next;
+};
+
+static struct interp_list *free_interps = NULL;
+
static pthread_key_t sandwich_per_thread_info_key;

/* {{{ sandwich SAPI Details */
@@ -88,7 +95,7 @@ static sapi_module_struct sandwich_sapi
"sandwich",
"Ham and Cheese",
NULL, /* startup */
- NULL, /* shutdown */
+ zend_shutdown, /* shutdown */
NULL, /* activate */
NULL, /* deactivate */
sandwich_sapi_ub_write,
@@ -151,6 +158,23 @@ sandwich_per_interp *sandwich_per_interp
{
/* if (!conf->eval_ok) return NULL; */
sandwich_per_interp *info;
+ if(free_interps) {
+ struct interp_list *tofree = free_interps;
+ info = free_interps->interp;
+ free_interps = free_interps->next;
+ free(tofree);
+ /* return interpreter to working state */
+ INTERP_CTX_ENTER(info->ctx);
+ {
+ TSRMLS_FETCH();
+ php_request_startup(TSRMLS_C);
+ info->ref = 1;
+ PG(during_request_startup) = 0;
+ SandwichG(php) = info;
+ INTERP_CTX_LEAVE();
+ }
+ return info;
+ }

#ifndef ZTS
if(one_true_interp) return one_true_interp;
@@ -198,14 +222,16 @@ void sandwich_per_interp_shutdown(sandwi

INTERP_CTX_ENTER(interp->ctx);
{
+ struct interp_list *node;
TSRMLS_FETCH();
php_request_shutdown(NULL);
- INTERP_CTX_LEAVE();
#ifdef ZTS
- tsrm_free_interpreter_context(interp->ctx);
+ tsrm_set_interpreter_context(NULL);
+ node = malloc(sizeof(*node));
+ node->interp = interp;
+ node->next = free_interps;
+ free_interps = node;
#endif
- interp->ctx = NULL;
- free(interp);
}
INTERP_CTX_LEAVE();
}
reply

Search Discussions

Related Discussions

Discussion Navigation
viewthread | post

1 user in discussion

Gschlossnagle: 1 post