]> granicus.if.org Git - php/commitdiff
MFB (Fix several egregious leaks in ext/browscap and sapi/embed).
authorAndrei Zmievski <andrei@php.net>
Tue, 25 Jan 2005 21:33:58 +0000 (21:33 +0000)
committerAndrei Zmievski <andrei@php.net>
Tue, 25 Jan 2005 21:33:58 +0000 (21:33 +0000)
ext/standard/browscap.c
sapi/embed/php_embed.c

index 2baf3735b1ae57c192205ceeb97beaa8bea68529..77534f410ceb6d4788ee162b9da92fd0486f211e 100644 (file)
@@ -33,12 +33,17 @@ static zval *current_section;
 
 /* OBJECTS_FIXME: This whole extension needs going through. The use of objects looks pretty broken here */
 
-static void browscap_entry_dtor(zval *pvalue)
+static void browscap_entry_dtor(zval **pvalue)
 {
-       if (Z_TYPE_P(pvalue) == IS_ARRAY) {
-               zend_hash_destroy(Z_ARRVAL_P(pvalue));
-               free(Z_ARRVAL_P(pvalue));
+       if (Z_TYPE_PP(pvalue) == IS_ARRAY) {
+               zend_hash_destroy(Z_ARRVAL_PP(pvalue));
+               free(Z_ARRVAL_PP(pvalue));
+       } else if (Z_TYPE_PP(pvalue) == IS_STRING) {
+               if (Z_STRVAL_PP(pvalue) && Z_STRVAL_PP(pvalue) != empty_string) {
+                       free(Z_STRVAL_PP(pvalue));
+               }
        }
+       free(*pvalue);
 }
 
 /* {{{ convert_browscap_pattern
@@ -97,7 +102,7 @@ static void php_browscap_parser_cb(zval *arg1, zval *arg2, int callback_type, vo
 
                                new_property = (zval *) malloc(sizeof(zval));
                                INIT_PZVAL(new_property);
-                               Z_STRVAL_P(new_property) = Z_STRLEN_P(arg2)?zend_strndup(Z_STRVAL_P(arg2), Z_STRLEN_P(arg2)):"";
+                               Z_STRVAL_P(new_property) = Z_STRLEN_P(arg2)?zend_strndup(Z_STRVAL_P(arg2), Z_STRLEN_P(arg2)):empty_string;
                                Z_STRLEN_P(new_property) = Z_STRLEN_P(arg2);
                                Z_TYPE_P(new_property) = IS_STRING;
 
@@ -123,6 +128,7 @@ static void php_browscap_parser_cb(zval *arg1, zval *arg2, int callback_type, vo
                                section_properties = (HashTable *) malloc(sizeof(HashTable));
                                zend_hash_init(section_properties, 0, NULL, (dtor_func_t) browscap_entry_dtor, 1);
                                current_section->value.ht = section_properties;
+                               current_section->type = IS_ARRAY;
                                zend_hash_update(&browser_hash, Z_STRVAL_P(arg1), Z_STRLEN_P(arg1)+1, (void *) &current_section, sizeof(zval *), NULL);
 
                                Z_STRVAL_P(processed) = Z_STRVAL_P(arg1);
index 57425043c3ee20b83ba944071223ba7baaed9ab3..486b8d5b865f26e8ec625429482bc7306dfe2a4e 100644 (file)
@@ -211,6 +211,7 @@ void php_embed_shutdown(TSRMLS_D)
 {
        php_request_shutdown((void *) 0);
        php_module_shutdown(TSRMLS_C);
+       sapi_shutdown();
 #ifdef ZTS
     tsrm_shutdown();
 #endif