Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix memory leak in zim_Phalcon_Tag__inputField() #1700

Merged
merged 3 commits into from Dec 18, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
1.3.0
- Code cleanup: get rid of compiler warnings, dead code elimination, code deduplication, use static code analysers to eliminate possible bugs
(#801, #802, #810, #825, #827, #838, #849, #942, #968, #1001, #1093, #1169, #1214, #1223, #1224, #1375, #1430)
- Fixed various memory leaks (#469, #860, #910, #914, #916, #1031, #1067, #1249, #1273, #1291, #1309, #1345, #1455, #1470)
- Fixed various memory leaks (#469, #860, #910, #914, #916, #1031, #1067, #1249, #1273, #1291, #1309, #1345, #1455, #1470, #1700)
- Fixed memory access violations / segmentation faults / etc (#469, #849, #851, #852, #858, #860, #861, #895, #911, #918, #927, #928, #1000, #1077, #1112, #1113, #1131, #1149, #1173,
#1272, #1284, #1302, #1340, #1343, #1368, #1369, #1371, #1376, #1379, #1392, #1451, #1466, #1485, #1494, #1501, #1504, #1509, #1567, #1607)
- Fixed PHP notices, warnings and other incompatibilities (#894, #1222, #1315, #1413, #1427, #1428, #1529)
Expand Down
15 changes: 7 additions & 8 deletions ext/tag.c
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ PHP_METHOD(Phalcon_Tag, getEscaperService){

PHALCON_VERIFY_INTERFACE(dependency_injector, phalcon_diinterface_ce);

PHALCON_INIT_VAR(service);
PHALCON_ALLOC_GHOST_ZVAL(service);
PHALCON_ZVAL_MAYBE_INTERNED_STRING(service, phalcon_interned_escaper);

PHALCON_INIT_VAR(escaper);
Expand Down Expand Up @@ -622,8 +622,9 @@ PHP_METHOD(Phalcon_Tag, _inputField){
PHALCON_CPY_WRT_CTOR(params, parameters);
}

PHALCON_INIT_VAR(value);
if (PHALCON_IS_FALSE(as_value)) {
PHALCON_INIT_VAR(value);

if (!phalcon_array_isset_long_fetch(&id, params, 0)) {
PHALCON_OBS_VAR(id);
phalcon_array_fetch_string(&id, params, SL("id"), PH_NOISY);
Expand All @@ -638,8 +639,8 @@ PHP_METHOD(Phalcon_Tag, _inputField){
else {
phalcon_array_update_string(&params, ISL(name), &id, PH_COPY);
}
/**

/**
* Automatically assign the id if the name is not an array
*/
if (!phalcon_memnstr_str(id, SL("["))) {
Expand All @@ -651,12 +652,11 @@ PHP_METHOD(Phalcon_Tag, _inputField){
phalcon_call_self_p2(value, this_ptr, "getvalue", id, params);
phalcon_array_update_string(&params, ISL(value), &value, PH_COPY);
} else {
/**
/**
* Use the 'id' as value if the user hadn't set it
*/
if (!phalcon_array_isset_string(params, SS("value"))) {
if (phalcon_array_isset_long_fetch(&value, params, 0)) {
Z_ADDREF_P(value); /* because of PHALCON_INIT_VAR() */
phalcon_array_update_string(&params, ISL(value), &value, PH_COPY);
}
}
Expand Down Expand Up @@ -800,9 +800,8 @@ static void phalcon_tag_generic_field(INTERNAL_FUNCTION_PARAMETERS, const char*

phalcon_fetch_params(0, 1, 0, &parameters);

MAKE_STD_ZVAL(field_type);
PHALCON_ALLOC_GHOST_ZVAL(field_type);
ZVAL_STRING(field_type, type, 1);
Z_DELREF_P(field_type);

if (as_value) {
phalcon_call_self_func_params(return_value, return_value_ptr, this_ptr, SL("_inputfield") TSRMLS_CC, 3, field_type, parameters, PHALCON_GLOBAL(z_true));
Expand Down
12 changes: 12 additions & 0 deletions ext/tests/issue-1700.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
--TEST--
Memory leak in zim_Phalcon_Tag__inputField() - https://github.com/phalcon/cphalcon/pull/1700
--SKIPIF--
<?php include('skipif.inc'); ?>
--FILE--
<?php
$di = new \Phalcon\Di\FactoryDefault();
Phalcon\Tag::setAutoescape(true);
echo Phalcon\Tag::submitButton('ľščťžýáíéôňď'), PHP_EOL;
?>
--EXPECT--
<input type="submit" value="ľščťžýáíéôňď" />