Skip to content

Commit

Permalink
Tag select (#438)
Browse files Browse the repository at this point in the history
* Fix memory leak in Phalcon\Tag\Select::_optionsFromArray

* Fix memory leak in Phalcon\Translate\Adapter\*
  • Loading branch information
dreamsxin authored Mar 22, 2019
1 parent 6676240 commit 27cd0a1
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 14 deletions.
1 change: 0 additions & 1 deletion ext/tag/select.c
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,6 @@ PHP_METHOD(Phalcon_Tag_Select, _optionsFromArray){
PHALCON_MM_ADD_ENTRY(&code);
zval_ptr_dtor(&v);
}
zval_ptr_dtor(&escaped);
} else {
zval array_options = {}, escaped = {};
phalcon_htmlspecialchars(&escaped, &option_value, NULL, NULL);
Expand Down
23 changes: 14 additions & 9 deletions ext/translate/adapter/gettext.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
+------------------------------------------------------------------------+
| Authors: Andres Gutierrez <[email protected]> |
| Eduar Carvajal <[email protected]> |
| ZhuZongXin <[email protected]> |
+------------------------------------------------------------------------+
*/

Expand Down Expand Up @@ -164,13 +165,14 @@ PHP_METHOD(Phalcon_Translate_Adapter_Gettext, query){
zend_string *str_key;
ulong idx;

phalcon_fetch_params(0, 1, 2, &index, &placeholders, &domain);
phalcon_fetch_params(1, 1, 2, &index, &placeholders, &domain);

if (!domain) {
PHALCON_CALL_FUNCTION(&translation, "gettext", index);
PHALCON_MM_CALL_FUNCTION(&translation, "gettext", index);
} else {
PHALCON_CALL_FUNCTION(&translation, "dgettext", domain, index);
PHALCON_MM_CALL_FUNCTION(&translation, "dgettext", domain, index);
}
PHALCON_MM_ADD_ENTRY(&translation);

if (placeholders && Z_TYPE_P(placeholders) == IS_ARRAY && zend_hash_num_elements(Z_ARRVAL_P(placeholders))) {
ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(placeholders), idx, str_key, value) {
Expand All @@ -182,14 +184,16 @@ PHP_METHOD(Phalcon_Translate_Adapter_Gettext, query){
}

PHALCON_CONCAT_SVS(&key_placeholder, "%", &key, "%");
PHALCON_MM_ADD_ENTRY(&key_placeholder);

PHALCON_STR_REPLACE(&replaced, &key_placeholder, value, &translation);
PHALCON_MM_ADD_ENTRY(&replaced);

ZVAL_COPY_VALUE(&translation, &replaced);
} ZEND_HASH_FOREACH_END();
}

RETURN_CTOR(&translation);
RETURN_MM_CTOR(&translation);
}

/**
Expand All @@ -202,17 +206,18 @@ PHP_METHOD(Phalcon_Translate_Adapter_Gettext, exists){

zval *index, *domain = NULL, translation = {};

phalcon_fetch_params(0, 1, 1, &index, &domain);
phalcon_fetch_params(1, 1, 1, &index, &domain);

if (!domain) {
PHALCON_CALL_FUNCTION(&translation, "gettext", index);
PHALCON_MM_CALL_FUNCTION(&translation, "gettext", index);
} else {
PHALCON_CALL_FUNCTION(&translation, "dgettext", domain, index);
PHALCON_MM_CALL_FUNCTION(&translation, "dgettext", domain, index);
}
PHALCON_MM_ADD_ENTRY(&translation);

if (Z_STRLEN(translation) > 0) {
RETURN_TRUE;
RETURN_MM_TRUE;
}

RETURN_FALSE;
RETURN_MM_FALSE;
}
7 changes: 5 additions & 2 deletions ext/translate/adapter/nativearray.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
+------------------------------------------------------------------------+
| Authors: Andres Gutierrez <[email protected]> |
| Eduar Carvajal <[email protected]> |
| ZhuZongXin <[email protected]> |
+------------------------------------------------------------------------+
*/

Expand Down Expand Up @@ -111,7 +112,7 @@ PHP_METHOD(Phalcon_Translate_Adapter_NativeArray, query){
zend_string *str_key;
ulong idx;

phalcon_fetch_params(0, 1, 1, &index, &placeholders);
phalcon_fetch_params(1, 1, 1, &index, &placeholders);

if (!placeholders) {
placeholders = &PHALCON_GLOBAL(z_null);
Expand All @@ -132,14 +133,16 @@ PHP_METHOD(Phalcon_Translate_Adapter_NativeArray, query){
}

PHALCON_CONCAT_SVS(&key_placeholder, "%", &key, "%");
PHALCON_MM_ADD_ENTRY(&key_placeholder);

PHALCON_STR_REPLACE(&replaced, &key_placeholder, value, &translation);
PHALCON_MM_ADD_ENTRY(&replaced);

ZVAL_COPY_VALUE(&translation, &replaced);
} ZEND_HASH_FOREACH_END();
}

RETURN_CTOR(&translation);
RETURN_MM_CTOR(&translation);
}

/**
Expand Down
7 changes: 5 additions & 2 deletions ext/translate/adapter/php.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
+------------------------------------------------------------------------+
| Authors: Andres Gutierrez <[email protected]> |
| Eduar Carvajal <[email protected]> |
| ZhuZongXin <[email protected]> |
+------------------------------------------------------------------------+
*/

Expand Down Expand Up @@ -134,7 +135,7 @@ PHP_METHOD(Phalcon_Translate_Adapter_Php, query){
zend_string *str_key;
ulong idx;

phalcon_fetch_params(0, 1, 1, &index, &placeholders);
phalcon_fetch_params(1, 1, 1, &index, &placeholders);

if (!placeholders) {
placeholders = &PHALCON_GLOBAL(z_null);
Expand All @@ -155,14 +156,16 @@ PHP_METHOD(Phalcon_Translate_Adapter_Php, query){
}

PHALCON_CONCAT_SVS(&key_placeholder, "%", &key, "%");
PHALCON_MM_ADD_ENTRY(&key_placeholder);

PHALCON_STR_REPLACE(&replaced, &key_placeholder, value, &translation);
PHALCON_MM_ADD_ENTRY(&replaced);

ZVAL_COPY_VALUE(&translation, &replaced);
} ZEND_HASH_FOREACH_END();
}

RETURN_CTOR(&translation);
RETURN_MM_CTOR(&translation);
}

/**
Expand Down

0 comments on commit 27cd0a1

Please sign in to comment.