Skip to content

Commit

Permalink
fix memleaks
Browse files Browse the repository at this point in the history
  • Loading branch information
laruence committed Sep 9, 2012
1 parent d9135ee commit ef0467d
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 37 deletions.
2 changes: 1 addition & 1 deletion tests/048.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Check for Sample application
--INI--
yaf.use_spl_autoload=0
yaf.lowcase_path=0
report_memleaks=0

--FILE--
<?php
require "build.inc";
Expand Down
2 changes: 1 addition & 1 deletion tests/049.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Check for Sample application with exception
--INI--
yaf.use_spl_autoload=0
yaf.lowcase_path=0
report_memleaks=0

--FILE--
<?php
require "build.inc";
Expand Down
2 changes: 1 addition & 1 deletion tests/050.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Check for Sample application with return response
--INI--
yaf.use_spl_autoload=0
yaf.lowcase_path=0
report_memleaks=0

--FILE--
<?php
require "build.inc";
Expand Down
26 changes: 17 additions & 9 deletions yaf_controller.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
+----------------------------------------------------------------------+
*/

/* $Id: yaf_controller.c 327425 2012-09-02 03:58:49Z laruence $ */
/* $Id: yaf_controller.c 327558 2012-09-09 05:59:24Z laruence $ */

#ifdef HAVE_CONFIG_H
#include "config.h"
Expand Down Expand Up @@ -79,7 +79,7 @@ ZEND_END_ARG_INFO()

/** {{{ zval * yaf_controller_render(yaf_controller_t *instance, char *action_name, int len, zval *var_array TSRMLS_DC)
*/
static zval * yaf_controller_render(yaf_controller_t *instance, char *action_name, int len, zval *var_array TSRMLS_DC) {
zval * yaf_controller_render(yaf_controller_t *instance, char *action_name, int len, zval *var_array TSRMLS_DC) {
char *path, *view_ext, *self_name, *tmp;
zval *name, *param, *ret = NULL;
int path_len;
Expand Down Expand Up @@ -134,7 +134,13 @@ static zval * yaf_controller_render(yaf_controller_t *instance, char *action_nam
}
}

if (!ret || EG(exception)) {
if (!ret) {
zval_ptr_dtor(&param);
return NULL;
}

if (EG(exception)) {
zval_ptr_dtor(&ret);
zval_ptr_dtor(&param);
return NULL;
}
Expand All @@ -151,17 +157,17 @@ static zval * yaf_controller_render(yaf_controller_t *instance, char *action_nam
}
/* }}} */

/** {{{ static int yaf_controller_display(zend_class_entry *ce, yaf_controller_t *instance, char *action_name, int len, zval *var_array TSRMLS_DC)
/** {{{ int yaf_controller_display(yaf_controller_t *instance, char *action_name, int len, zval *var_array TSRMLS_DC)
*/
static int yaf_controller_display(zend_class_entry *ce, yaf_controller_t *instance, char *action_name, int len, zval *var_array TSRMLS_DC) {
int yaf_controller_display(yaf_controller_t *instance, char *action_name, int len, zval *var_array TSRMLS_DC) {
char *path, *view_ext, *self_name, *tmp;
zval *name, *param, *ret = NULL;
int path_len;
yaf_view_t *view;
zend_class_entry *view_ce;

view = zend_read_property(ce, instance, ZEND_STRL(YAF_CONTROLLER_PROPERTY_NAME_VIEW), 1 TSRMLS_CC);
name = zend_read_property(ce, instance, ZEND_STRL(YAF_CONTROLLER_PROPERTY_NAME_NAME), 1 TSRMLS_CC);
view = zend_read_property(yaf_controller_ce, instance, ZEND_STRL(YAF_CONTROLLER_PROPERTY_NAME_VIEW), 1 TSRMLS_CC);
name = zend_read_property(yaf_controller_ce, instance, ZEND_STRL(YAF_CONTROLLER_PROPERTY_NAME_NAME), 1 TSRMLS_CC);
view_ext = YAF_G(view_ext);

self_name = zend_str_tolower_dup(Z_STRVAL_P(name), Z_STRLEN_P(name));
Expand Down Expand Up @@ -496,7 +502,9 @@ PHP_METHOD(yaf_controller, render) {
} else {
zval *output = yaf_controller_render(getThis(), action_name, action_name_len, var_array TSRMLS_CC);
if (output) {
RETURN_ZVAL(output, 0, 0);
ZVAL_STRINGL(return_value, Z_STRVAL_P(output), Z_STRLEN_P(output), 0);
efree(output);
return;
} else {
RETURN_FALSE;
}
Expand All @@ -514,7 +522,7 @@ PHP_METHOD(yaf_controller, display) {
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|z", &action_name, &action_name_len, &var_array) == FAILURE) {
return;
} else {
RETURN_BOOL(yaf_controller_display(yaf_controller_ce, getThis(), action_name, action_name_len, var_array TSRMLS_CC));
RETURN_BOOL(yaf_controller_display(getThis(), action_name, action_name_len, var_array TSRMLS_CC));
}
}
/* }}} */
Expand Down
4 changes: 3 additions & 1 deletion yaf_controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
+----------------------------------------------------------------------+
*/

/* $Id: yaf_controller.h 324667 2012-03-31 13:55:08Z laruence $ */
/* $Id: yaf_controller.h 327558 2012-09-09 05:59:24Z laruence $ */

#ifndef YAF_CONTROLLER_H
#define YAF_CONTROLLER_H
Expand All @@ -33,6 +33,8 @@
extern zend_class_entry *yaf_controller_ce;
int yaf_controller_construct(zend_class_entry *ce, yaf_controller_t *self,
yaf_request_t *request, yaf_response_t *response, yaf_view_t *view, zval *args TSRMLS_DC);
zval * yaf_controller_render(zval *instance, char *action_name, int len, zval *var_array TSRMLS_DC);
int yaf_controller_display(zval *instance, char *action_name, int len, zval *var_array TSRMLS_DC);
YAF_STARTUP_FUNCTION(controller);
#endif
/*
Expand Down
77 changes: 55 additions & 22 deletions yaf_dispatcher.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
+----------------------------------------------------------------------+
*/

/* $Id: yaf_dispatcher.c 327557 2012-09-09 05:11:59Z laruence $ */
/* $Id: yaf_dispatcher.c 327558 2012-09-09 05:59:24Z laruence $ */

#ifdef HAVE_CONFIG_H
#include "config.h"
Expand Down Expand Up @@ -751,31 +751,58 @@ int yaf_dispatcher_handle(yaf_dispatcher_t *dispatcher, yaf_request_t *request,

if (auto_render) {
ret = NULL;
if (!Z_BVAL_P(instantly_flush)) {
zend_call_method_with_1_params(&executor, ce, NULL, "render", &ret, action);
zval_ptr_dtor(&executor);

if (ret && Z_TYPE_P(ret) == IS_STRING && Z_STRLEN_P(ret)) {
yaf_response_alter_body(response, NULL, 0, Z_STRVAL_P(ret), Z_STRLEN_P(ret), YAF_RESPONSE_APPEND TSRMLS_CC);
zval_ptr_dtor(&ret);
} else if (ret) {
zval_ptr_dtor(&ret);
if (ce == yaf_controller_ce || ce == yaf_action_ce) {
if (!Z_BVAL_P(instantly_flush)) {
ret = yaf_controller_render(executor, Z_STRVAL_P(action), Z_STRLEN_P(action), NULL TSRMLS_CC);
zval_ptr_dtor(&executor);
zval_ptr_dtor(&action);
if (ret) {
yaf_response_alter_body(response, NULL, 0, Z_STRVAL_P(ret), Z_STRLEN_P(ret), YAF_RESPONSE_APPEND TSRMLS_CC);
zval_ptr_dtor(&ret);
return 1;
}
return 0;
}
} else {
zend_call_method_with_1_params(&executor, ce, NULL, "display", &ret, action);
zval_ptr_dtor(&executor);

if (!ret) {
} else {
if (yaf_controller_display(executor, Z_STRVAL_P(action), Z_STRLEN_P(action), NULL TSRMLS_CC)) {
zval_ptr_dtor(&executor);
zval_ptr_dtor(&action);
return 1;
}
zval_ptr_dtor(&executor);
zval_ptr_dtor(&action);
return 0;
}

if ((Z_TYPE_P(ret) == IS_BOOL && !Z_BVAL_P(ret))) {
zval_ptr_dtor(&ret);
zval_ptr_dtor(&action);
return 0;
} else {
if (!Z_BVAL_P(instantly_flush)) {
zend_call_method_with_1_params(&executor, ce, NULL, "render", &ret, action);
zval_ptr_dtor(&executor);

if (ret && Z_TYPE_P(ret) == IS_STRING && Z_STRLEN_P(ret)) {
yaf_response_alter_body(response, NULL, 0, Z_STRVAL_P(ret), Z_STRLEN_P(ret), YAF_RESPONSE_APPEND TSRMLS_CC);
zval_ptr_dtor(&ret);
} else if (ret) {
zval_ptr_dtor(&ret);
zval_ptr_dtor(&action);
return 0;
}
} else {
zend_call_method_with_1_params(&executor, ce, NULL, "display", &ret, action);
zval_ptr_dtor(&executor);

if (!ret) {
zval_ptr_dtor(&action);
return 0;
}

if ((Z_TYPE_P(ret) == IS_BOOL && !Z_BVAL_P(ret))) {
zval_ptr_dtor(&ret);
zval_ptr_dtor(&action);
return 0;
} else {
zval_ptr_dtor(&ret);
zval_ptr_dtor(&action);
return 1;
}
}
}
} else {
Expand Down Expand Up @@ -827,7 +854,13 @@ void yaf_dispatcher_exception_handler(yaf_dispatcher_t *dispatcher, yaf_request_
zval_ptr_dtor(&action);

/** use $request->getException() instand of */
yaf_request_set_params_single(request, ZEND_STRL("exception"), exception TSRMLS_CC);
if (yaf_request_set_params_single(request, ZEND_STRL("exception"), exception TSRMLS_CC)) {
zval_ptr_dtor(&exception);
} else {
/* failover to uncaught exception */
EG(exception) = exception;
return;
}
yaf_request_set_dispatched(request, 0 TSRMLS_CC);

view = yaf_dispatcher_init_view(dispatcher, NULL, NULL TSRMLS_CC);
Expand Down
7 changes: 5 additions & 2 deletions yaf_loader.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
+----------------------------------------------------------------------+
*/

/* $Id: yaf_loader.c 327520 2012-09-07 07:59:08Z laruence $ */
/* $Id: yaf_loader.c 327558 2012-09-09 05:59:24Z laruence $ */

#ifdef HAVE_CONFIG_H
#include "config.h"
Expand Down Expand Up @@ -854,7 +854,8 @@ PHP_METHOD(yaf_loader, autoload) {
if (!YAF_G(use_spl_autoload)) {
/** directory might be NULL since we passed a NULL */
if (yaf_internal_autoload(file_name, file_name_len, &directory TSRMLS_CC)) {
if (zend_hash_exists(EG(class_table), zend_str_tolower_dup(origin_classname, class_name_len), class_name_len + 1)) {
char *lc_classname = zend_str_tolower_dup(origin_classname, class_name_len);
if (zend_hash_exists(EG(class_table), lc_classname, class_name_len + 1)) {
#ifdef YAF_HAVE_NAMESPACE
if (origin_lcname) {
efree(origin_lcname);
Expand All @@ -868,8 +869,10 @@ PHP_METHOD(yaf_loader, autoload) {
efree(file_name);
}

efree(lc_classname);
RETURN_TRUE;
} else {
efree(lc_classname);
php_error_docref(NULL TSRMLS_CC, E_STRICT, "Could not find class %s in %s", class_name, directory);
}
} else {
Expand Down

0 comments on commit ef0467d

Please sign in to comment.