com php-src: Fixed memory leak: ext/intl/msgformat/msgformat_ helpers.cpp
| From: | Xinchen Hui | Date: | Sun, 29 Jun 2014 11:46:01 +0000 |
| Subject: | com php-src: Fixed memory leak: ext/intl/msgformat/msgformat_ helpers.cpp | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-79131@lists.php.net to get a copy of this message | ||
Commit: f466be5e9b8f181d135a9f279138e121062f2b8b
Author: Xinchen Hui <laruence@php.net> Sun, 29 Jun 2014 19:46:01 +0800
Parents: a94ec141fe35b2e6351f55f8ca796ec4ef332de5
Branches: phpng
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=f466be5e9b8f181d135a9f279138e121062f2b8b
Log:
Fixed memory leak
Changed paths:
M ext/intl/msgformat/msgformat_helpers.cpp
Diff:
diff --git a/ext/intl/msgformat/msgformat_helpers.cpp b/ext/intl/msgformat/msgformat_helpers.cpp
index b0dd292..fc7315a 100644
--- a/ext/intl/msgformat/msgformat_helpers.cpp
+++ b/ext/intl/msgformat/msgformat_helpers.cpp
@@ -83,6 +83,10 @@ U_CFUNC int32_t umsg_format_arg_count(UMessageFormat *fmt)
return fmt_count;
}
+static void arg_types_dtor(zval *el TSRMLS_DC) {
+ efree(Z_PTR_P(el));
+}
+
static HashTable *umsg_get_numeric_types(MessageFormatter_object *mfo,
intl_error& err TSRMLS_DC)
{
@@ -104,7 +108,7 @@ static HashTable *umsg_get_numeric_types(MessageFormatter_object *mfo,
/* Hash table will store Formattable::Type objects directly,
* so no need for destructor */
ALLOC_HASHTABLE(ret);
- zend_hash_init(ret, parts_count, NULL, NULL, 0);
+ zend_hash_init(ret, parts_count, NULL, arg_types_dtor, 0);
for (int i = 0; i < parts_count; i++) {
const Formattable::Type t = types[i];
@@ -151,7 +155,7 @@ static HashTable *umsg_parse_format(MessageFormatter_object *mfo,
/* Hash table will store Formattable::Type objects directly,
* so no need for destructor */
ALLOC_HASHTABLE(ret);
- zend_hash_init(ret, 32, NULL, NULL, 0);
+ zend_hash_init(ret, 32, NULL, arg_types_dtor, 0);
parts_count = mp.countParts();
@@ -179,12 +183,11 @@ static HashTable *umsg_parse_format(MessageFormatter_object *mfo,
if (name_part.getType() == UMSGPAT_PART_TYPE_ARG_NAME) {
UnicodeString argName = mp.getSubstring(name_part);
- if (zend_hash_find(ret, (char*)argName.getBuffer(), argName.length(),
- (void**)&storedType) == FAILURE) {
+ if ((storedType = zend_hash_str_find_ptr(ret, (char*)argName.getBuffer(), argName.length())) ==
NULL) {
/* not found already; create new entry in HT */
Formattable::Type bogusType = Formattable::kObject;
- if (zend_hash_update(ret, (char*)argName.getBuffer(), argName.length(),
- (void*)&bogusType, sizeof(bogusType), (void**)&storedType) == FAILURE) {
+ if ((storedType = zend_hash_str_update_mem(ret, (char*)argName.getBuffer(), argName.length(),
+ (void*)&bogusType, sizeof(bogusType))) == NULL) {
intl_errors_set(&err, U_MEMORY_ALLOCATION_ERROR,
"Write to argument types hash table failed", 0 TSRMLS_CC);
continue;
@@ -197,12 +200,10 @@ static HashTable *umsg_parse_format(MessageFormatter_object *mfo,
"Found part with negative number", 0 TSRMLS_CC);
continue;
}
- if (zend_hash_index_find(ret, (ulong)argNumber, (void**)&storedType)
- == FAILURE) {
+ if ((storedType = zend_hash_index_find_ptr(ret, (ulong)argNumber)) == NULL) {
/* not found already; create new entry in HT */
Formattable::Type bogusType = Formattable::kObject;
- if (zend_hash_index_update(ret, (ulong)argNumber, (void*)&bogusType,
- sizeof(bogusType), (void**)&storedType) == FAILURE) {
+ if ((storedType = zend_hash_index_update_mem(ret, (ulong)argNumber, (void*)&bogusType,
sizeof(bogusType))) == NULL) {
intl_errors_set(&err, U_MEMORY_ALLOCATION_ERROR,
"Write to argument types hash table failed", 0 TSRMLS_CC);
continue;