Skip to content

Commit

Permalink
fix memory leak of zoneAlias
Browse files Browse the repository at this point in the history
  • Loading branch information
hetao committed Oct 28, 2016
1 parent c27de79 commit c831ed7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
10 changes: 7 additions & 3 deletions pecl/slightphp.c
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,7 @@ PHP_METHOD(slightphp, run)
add_next_index_string(path_array, Z_STRVAL_P(entry), 1);
}
//{{{
zval *zone_alias=NULL;
zval *zoneAlias = zend_read_static_property(slightphp_ce_ptr,"zoneAlias",sizeof("zoneAlias")-1,1 TSRMLS_CC);
if(zoneAlias && Z_TYPE_P(zoneAlias)==IS_ARRAY){
char *string_key;uint str_key_len;ulong num_key;
Expand All @@ -438,14 +439,14 @@ PHP_METHOD(slightphp, run)
if(strcmp(Z_STRVAL_PP(entry2) ,Z_STRVAL_P(zone))==0){
switch (zend_hash_get_current_key_ex(Z_ARRVAL_P(zoneAlias), &string_key, &str_key_len, &num_key, 0, &pos)) {
case HASH_KEY_IS_STRING:
ZVAL_STRING(zone,string_key,1);
MAKE_STD_ZVAL(zone_alias);
ZVAL_STRING(zone_alias,string_key,0);
zone=zone_alias;
break;
}
}
zend_hash_move_forward_ex(Z_ARRVAL_P(zoneAlias), &pos);
}
if(entry2)zval_ptr_dtor(entry2);
if(string_key)efree(string_key);
}
//}}}
if(!isPart){
Expand All @@ -461,6 +462,7 @@ PHP_METHOD(slightphp, run)
strcmp(Z_STRVAL_P(entry),Z_STRVAL_P(zend_read_static_property(slightphp_ce_ptr,"entry",sizeof("entry")-1,1 TSRMLS_CC)))==0
){
debug("part ignored [%s]",Z_STRVAL_P(url));
if(zone_alias)zval_ptr_dtor(&zone_alias);
zval_ptr_dtor(&url);
zval_ptr_dtor(&path_array);
return;
Expand All @@ -470,11 +472,13 @@ PHP_METHOD(slightphp, run)
zval *appDir = zend_read_static_property(slightphp_ce_ptr,"appDir",sizeof("appDir")-1,1 TSRMLS_CC);
if(slightphp_load(appDir,zone,page TSRMLS_CC) == SUCCESS){
if(slightphp_run(zone,page,entry,return_value,1,&path_array TSRMLS_CC)==SUCCESS){
if(zone_alias)zval_ptr_dtor(&zone_alias);
zval_ptr_dtor(&url);
zval_ptr_dtor(&path_array);
RETURN_ZVAL(return_value,0,0);
};
}
if(zone_alias)zval_ptr_dtor(&zone_alias);
zval_ptr_dtor(&url);
zval_ptr_dtor(&path_array);
RETURN_FALSE;
Expand Down
15 changes: 8 additions & 7 deletions pecl/slightphp7.c
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ PHP_METHOD(slightphp, getZoneAlias)
zval *zoneAlias = zend_read_static_property(slightphp_ce_ptr,"zoneAlias",sizeof("zoneAlias")-1,1 );
if(!zoneAlias || Z_TYPE_P(zoneAlias)!=IS_ARRAY){ RETURN_FALSE; }
zval *token;
if((token = zend_hash_find(Z_ARRVAL_P(zoneAlias),zend_string_init(zone, strlen(zone) , 0))) != NULL) {
if ((token= zend_hash_str_find(Z_ARRVAL_P(zoneAlias), zone,zone_len)) != NULL){
*return_value = *token;
zval_copy_ctor(return_value);
}else{
Expand Down Expand Up @@ -379,18 +379,18 @@ PHP_METHOD(slightphp, run)

zval *entry2=NULL;
zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(zoneAlias), &pos);
while ((pos = zend_hash_get_current_data_ex(Z_ARRVAL_P(zoneAlias), (void *)entry2 ) == SUCCESS)) {
for (;; zend_hash_move_forward_ex(Z_ARRVAL_P(zoneAlias), &pos)) {
if (NULL == (entry2= zend_hash_get_current_data_ex(Z_ARRVAL_P(zoneAlias), &pos))) {
break;
}
if(strcmp(Z_STRVAL_P(entry2) ,Z_STRVAL_P(zone))==0){
switch (pos = zend_hash_get_current_key_ex(Z_ARRVAL_P(zoneAlias), &string_key, &num_key,&pos)) {
case HASH_KEY_IS_STRING:
ZVAL_NEW_STR(zone,string_key);
ZVAL_STR_COPY(zone,string_key);
break;
}
}
zend_hash_move_forward_ex(Z_ARRVAL_P(zoneAlias), &pos);
}
if(entry2)zval_ptr_dtor(entry2);
if(string_key)zend_string_release(string_key);
}
//}}}
if(!isPart){
Expand All @@ -406,6 +406,8 @@ PHP_METHOD(slightphp, run)
strcmp(Z_STRVAL_P(entry),Z_STRVAL_P(zend_read_static_property(slightphp_ce_ptr,"entry",sizeof("entry")-1,1 )))==0
){
debug("part ignored [%s]",Z_STRVAL(url));
zval_dtor(&path_array);
zval_dtor(&url);
return;
}
}
Expand All @@ -418,7 +420,6 @@ PHP_METHOD(slightphp, run)
zval_dtor(&url);
RETURN_ZVAL(&ret,0,1);
};
zval_dtor(&ret);
}
zval_dtor(&url);
zval_dtor(&path_array);
Expand Down

0 comments on commit c831ed7

Please sign in to comment.