]> granicus.if.org Git - php/commitdiff
Fixed memory leak
authorXinchen Hui <laruence@php.net>
Sun, 29 Jun 2014 11:46:01 +0000 (19:46 +0800)
committerXinchen Hui <laruence@php.net>
Sun, 29 Jun 2014 11:46:01 +0000 (19:46 +0800)
ext/intl/msgformat/msgformat_helpers.cpp

index b0dd2928430597d40b2fa9f3e83b0d1670ab5d7d..fc7315aefc97259041d27badb4ed5bd754828e6d 100644 (file)
@@ -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;