From 14a9a931862fe1fa85d086646a448668abc5d29a Mon Sep 17 00:00:00 2001 From: Vladimir Kolesnikov Date: Sun, 15 Dec 2013 21:35:35 +0200 Subject: [PATCH 1/3] Fix memory leak in zim_Phalcon_Tag__inputField() --- ext/tag.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/ext/tag.c b/ext/tag.c index c12869cb1c7..db9df4d09a3 100644 --- a/ext/tag.c +++ b/ext/tag.c @@ -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); @@ -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); @@ -638,8 +639,8 @@ PHP_METHOD(Phalcon_Tag, _inputField){ else { phalcon_array_update_string(¶ms, ISL(name), &id, PH_COPY); } - - /** + + /** * Automatically assign the id if the name is not an array */ if (!phalcon_memnstr_str(id, SL("["))) { @@ -651,12 +652,11 @@ PHP_METHOD(Phalcon_Tag, _inputField){ phalcon_call_self_p2(value, this_ptr, "getvalue", id, params); phalcon_array_update_string(¶ms, 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(¶ms, ISL(value), &value, PH_COPY); } } @@ -800,9 +800,8 @@ static void phalcon_tag_generic_field(INTERNAL_FUNCTION_PARAMETERS, const char* phalcon_fetch_params(0, 1, 0, ¶meters); - 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)); From 0f76c464f79c66bcdfff07c0f2877f8feafa21c1 Mon Sep 17 00:00:00 2001 From: Vladimir Kolesnikov Date: Sun, 15 Dec 2013 21:38:06 +0200 Subject: [PATCH 2/3] Updated CHANGELOG --- CHANGELOG | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG b/CHANGELOG index 8bd58cdf646..0477e5745d0 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -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) From aa2ec0f2cc61d74902869b2626a3ba66e5c7010e Mon Sep 17 00:00:00 2001 From: Vladimir Kolesnikov Date: Sun, 15 Dec 2013 21:39:59 +0200 Subject: [PATCH 3/3] Test case --- ext/tests/issue-1700.phpt | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 ext/tests/issue-1700.phpt diff --git a/ext/tests/issue-1700.phpt b/ext/tests/issue-1700.phpt new file mode 100644 index 00000000000..ccdfb3ad5ed --- /dev/null +++ b/ext/tests/issue-1700.phpt @@ -0,0 +1,12 @@ +--TEST-- +Memory leak in zim_Phalcon_Tag__inputField() - https://github.com/phalcon/cphalcon/pull/1700 +--SKIPIF-- + +--FILE-- + +--EXPECT-- +