Skip to content

Commit

Permalink
Fixed bug that $this is not Yaf_View_Simple in render method
Browse files Browse the repository at this point in the history
Fixed memleak in Yaf_View_Simple::display()
  • Loading branch information
laruence committed Sep 27, 2012
1 parent 6d09d18 commit 0e1f81c
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 27 deletions.
64 changes: 64 additions & 0 deletions tests/059.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
--TEST--
Check nesting view render
--SKIPIF--
<?php if (!extension_loaded("yaf")) print "skip"; ?>
--INI--
yaf.use_spl_autoload=0
yaf.lowcase_path=0
--FILE--
<?php
require "build.inc";
startup();

$config = array(
"application" => array(
"directory" => APPLICATION_PATH,
),
);

file_put_contents(APPLICATION_PATH . "/Bootstrap.php", <<<PHP
<?php
class Bootstrap extends Yaf_Bootstrap_Abstract {
public function _initReturn(Yaf_Dispatcher \$dispatcher) {
\$dispatcher->returnResponse(true);
}
}
PHP
);

file_put_contents(APPLICATION_PATH . "/controllers/Index.php", <<<PHP
<?php
class IndexController extends Yaf_Controller_Abstract {
public function init() {
Yaf_Dispatcher::getInstance()->flushInstantly(true);
}
public function indexAction() {
var_dump(\$this->_view->getScriptPath());
}
}
PHP
);

file_put_contents(APPLICATION_PATH . "/views/index/index.phtml", "<?print_r(\$this); \$this->display('index/sub.phtml', array('content' => 'dummy'));?>");
file_put_contents(APPLICATION_PATH . "/views/index/sub.phtml", "<?echo \$content; echo \$this->eval('foobar'); ?>");

$app = new Yaf_Application($config);
$response = $app->bootstrap()->run();
?>
--CLEAN--
<?php
require "build.inc";
shutdown();
?>
--EXPECTF--
string(%d) "%sviews"
Yaf_View_Simple Object
(
[_tpl_vars:protected] => Array
(
)

[_tpl_dir:protected] => %sapplication%cviews
[_options:protected] =>
)
dummyfoobar
45 changes: 18 additions & 27 deletions yaf_controller.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
+----------------------------------------------------------------------+
*/

/* $Id: yaf_controller.c 327580 2012-09-10 06:31:34Z laruence $ */
/* $Id: yaf_controller.c 327816 2012-09-27 10:10:04Z laruence $ */

#ifdef HAVE_CONFIG_H
#include "config.h"
Expand Down Expand Up @@ -119,40 +119,28 @@ zval * yaf_controller_render(yaf_controller_t *instance, char *action_name, int
ZVAL_STRINGL(param, path, path_len, 0);

view_ce = Z_OBJCE_P(view);
if (view_ce == yaf_view_simple_ce) {
MAKE_STD_ZVAL(ret);
if (!yaf_view_simple_render(view, param, var_array, ret TSRMLS_CC)) {
zval_ptr_dtor(&ret);
zval_ptr_dtor(&param);
return NULL;
}
if (var_array) {
zend_call_method_with_2_params(&view, view_ce, NULL, "render", &ret, param, var_array);
} else {
if (var_array) {
zend_call_method_with_2_params(&view, view_ce, NULL, "render", &ret, param, var_array);
} else {
zend_call_method_with_1_params(&view, view_ce, NULL, "render", &ret, param);
}
zend_call_method_with_1_params(&view, view_ce, NULL, "render", &ret, param);
}

zval_ptr_dtor(&param);

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

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

if (Z_TYPE_P(ret) == IS_BOOL && !Z_BVAL_P(ret)) {
zval_ptr_dtor(&param);
zval_ptr_dtor(&ret);
return NULL;
}

zval_ptr_dtor(&param);

return ret;
}
/* }}} */
Expand All @@ -173,7 +161,7 @@ int yaf_controller_display(yaf_controller_t *instance, char *action_name, int le
self_name = zend_str_tolower_dup(Z_STRVAL_P(name), Z_STRLEN_P(name));

tmp = self_name;
while (*tmp != '\0') {
while (*tmp != '\0') {
if (*tmp == '_') {
*tmp = DEFAULT_SLASH;
}
Expand All @@ -199,18 +187,19 @@ int yaf_controller_display(yaf_controller_t *instance, char *action_name, int le
ZVAL_STRINGL(param, path, path_len, 0);

view_ce = Z_OBJCE_P(view);
if (view_ce == yaf_view_simple_ce) {
yaf_view_simple_display(view, param, var_array, NULL TSRMLS_CC);
if (var_array) {
zend_call_method_with_2_params(&view, Z_OBJCE_P(view), NULL, "display", &ret, param, var_array);
} else {
if (var_array) {
zend_call_method_with_2_params(&view, Z_OBJCE_P(view), NULL, "display", &ret, param, var_array);
} else {
zend_call_method_with_1_params(&view, Z_OBJCE_P(view), NULL, "display", &ret, param);
}
zend_call_method_with_1_params(&view, Z_OBJCE_P(view), NULL, "display", &ret, param);
}
zval_ptr_dtor(&param);

if (!ret || EG(exception)) {
if (!ret) {
return 0;
}

if (EG(exception)) {
zval_ptr_dtor(&ret);
return 0;
}

Expand All @@ -219,6 +208,8 @@ int yaf_controller_display(yaf_controller_t *instance, char *action_name, int le
return 0;
}

zval_ptr_dtor(&ret);

return 1;
}
/* }}} */
Expand Down

0 comments on commit 0e1f81c

Please sign in to comment.