From: Dmitry Stogov Date: Wed, 13 Aug 2014 12:55:21 +0000 (+0400) Subject: cleanup X-Git-Tag: POST_PHPNG_MERGE~14^2~7 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=9fea4348fd7a3f8ed19d895a644bbd6c430b6dfe;p=php cleanup --- diff --git a/ext/standard/string.c b/ext/standard/string.c index 0b7cef3da8..dea319d7e7 100644 --- a/ext/standard/string.c +++ b/ext/standard/string.c @@ -3372,7 +3372,7 @@ PHPAPI zend_string *php_addcslashes(const char *str, int length, int should_free new_str = STR_REALLOC(new_str, newlen, 0); } if (should_free) { -//??? STR_FREE((char*)str); + efree((char*)str); } return new_str; } @@ -3417,7 +3417,7 @@ PHPAPI zend_string *php_addslashes(char *str, int length, int should_free TSRMLS *target = 0; if (should_free) { -//??? STR_FREE(str); + efree(str); } new_str = STR_REALLOC(new_str, target - new_str->val, 0); diff --git a/main/fopen_wrappers.c b/main/fopen_wrappers.c index ad2e8a8d14..981c5c5a15 100644 --- a/main/fopen_wrappers.c +++ b/main/fopen_wrappers.c @@ -433,16 +433,18 @@ PHPAPI int php_fopen_primary_script(zend_file_handle *file_handle TSRMLS_DC) if (!resolved_path) { if (SG(request_info).path_translated != filename) { -//??? STR_FREE(filename); - if (filename) efree(filename); + if (filename) { + efree(filename); + } } /* we have to free SG(request_info).path_translated here because * php_destroy_request_info assumes that it will get * freed when the include_names hash is emptied, but * we're not adding it in this case */ -//??? STR_FREE(SG(request_info).path_translated); - if (SG(request_info).path_translated) efree(SG(request_info).path_translated); - SG(request_info).path_translated = NULL; + if (SG(request_info).path_translated) { + efree(SG(request_info).path_translated); + SG(request_info).path_translated = NULL; + } return FAILURE; } efree(resolved_path); @@ -452,19 +454,22 @@ PHPAPI int php_fopen_primary_script(zend_file_handle *file_handle TSRMLS_DC) if (zend_stream_open(filename, file_handle TSRMLS_CC) == FAILURE) { PG(display_errors) = orig_display_errors; if (SG(request_info).path_translated != filename) { -//??? STR_FREE(filename); - if (filename) efree(filename); + if (filename) { + efree(filename); + } + } + if (SG(request_info).path_translated) { + efree(SG(request_info).path_translated); + SG(request_info).path_translated = NULL; } -//??? STR_FREE(SG(request_info).path_translated); /* for same reason as above */ - if (SG(request_info).path_translated) efree(SG(request_info).path_translated); - SG(request_info).path_translated = NULL; return FAILURE; } PG(display_errors) = orig_display_errors; if (SG(request_info).path_translated != filename) { -//??? STR_FREE(SG(request_info).path_translated); /* for same reason as above */ - if (SG(request_info).path_translated) efree(SG(request_info).path_translated); + if (SG(request_info).path_translated) { + efree(SG(request_info).path_translated); + } SG(request_info).path_translated = filename; } diff --git a/main/output.c b/main/output.c index 68f3fa11b9..41b2c65cdf 100644 --- a/main/output.c +++ b/main/output.c @@ -55,7 +55,7 @@ static HashTable php_output_handler_reverse_conflicts; static inline int php_output_lock_error(int op TSRMLS_DC); static inline void php_output_op(int op, const char *str, size_t len TSRMLS_DC); -static inline php_output_handler *php_output_handler_init(const char *name, size_t name_len, size_t chunk_size, int flags TSRMLS_DC); +static inline php_output_handler *php_output_handler_init(zend_string *name, size_t chunk_size, int flags TSRMLS_DC); static inline php_output_handler_status_t php_output_handler_op(php_output_handler *handler, php_output_context *context); static inline int php_output_handler_append(php_output_handler *handler, const php_output_buffer *buf TSRMLS_DC); static inline zval *php_output_handler_status(php_output_handler *handler, zval *entry); @@ -508,7 +508,7 @@ PHPAPI php_output_handler *php_output_handler_create_user(zval *output_handler, default: user = ecalloc(1, sizeof(php_output_handler_user_func_t)); if (SUCCESS == zend_fcall_info_init(output_handler, 0, &user->fci, &user->fcc, &handler_name, &error TSRMLS_CC)) { - handler = php_output_handler_init(handler_name->val, handler_name->len, chunk_size, (flags & ~0xf) | PHP_OUTPUT_HANDLER_USER TSRMLS_CC); + handler = php_output_handler_init(handler_name, chunk_size, (flags & ~0xf) | PHP_OUTPUT_HANDLER_USER TSRMLS_CC); ZVAL_COPY(&user->zoh, output_handler); handler->func.user = user; } else { @@ -532,9 +532,11 @@ PHPAPI php_output_handler *php_output_handler_create_user(zval *output_handler, PHPAPI php_output_handler *php_output_handler_create_internal(const char *name, size_t name_len, php_output_handler_context_func_t output_handler, size_t chunk_size, int flags TSRMLS_DC) { php_output_handler *handler; + zend_string *str = STR_INIT(name, name_len, 1); - handler = php_output_handler_init(name, name_len, chunk_size, (flags & ~0xf) | PHP_OUTPUT_HANDLER_INTERNAL TSRMLS_CC); + handler = php_output_handler_init(str, chunk_size, (flags & ~0xf) | PHP_OUTPUT_HANDLER_INTERNAL TSRMLS_CC); handler->func.internal = output_handler; + STR_RELEASE(str); return handler; } @@ -563,17 +565,17 @@ PHPAPI int php_output_handler_start(php_output_handler *handler TSRMLS_DC) if (php_output_lock_error(PHP_OUTPUT_HANDLER_START TSRMLS_CC) || !handler) { return FAILURE; } - if (NULL != (conflict = zend_hash_str_find_ptr(&php_output_handler_conflicts, handler->name, handler->name_len))) { - if (SUCCESS != conflict(handler->name, handler->name_len TSRMLS_CC)) { + if (NULL != (conflict = zend_hash_find_ptr(&php_output_handler_conflicts, handler->name))) { + if (SUCCESS != conflict(handler->name->val, handler->name->len TSRMLS_CC)) { return FAILURE; } } - if (NULL != (rconflicts = zend_hash_str_find_ptr(&php_output_handler_reverse_conflicts, handler->name, handler->name_len))) { + if (NULL != (rconflicts = zend_hash_find_ptr(&php_output_handler_reverse_conflicts, handler->name))) { for (zend_hash_internal_pointer_reset_ex(rconflicts, &pos); (conflict = zend_hash_get_current_data_ptr_ex(rconflicts, &pos)) != NULL; zend_hash_move_forward_ex(rconflicts, &pos) ) { - if (SUCCESS != conflict(handler->name, handler->name_len TSRMLS_CC)) { + if (SUCCESS != conflict(handler->name->val, handler->name->len TSRMLS_CC)) { return FAILURE; } } @@ -596,7 +598,7 @@ PHPAPI int php_output_handler_started(const char *name, size_t name_len TSRMLS_D handlers = (php_output_handler **) zend_stack_base(&OG(handlers)); for (i = 0; i < count; ++i) { - if (name_len == handlers[i]->name_len && !memcmp(handlers[i]->name, name, name_len)) { + if (name_len == handlers[i]->name->len && !memcmp(handlers[i]->name->val, name, name_len)) { return 1; } } @@ -715,10 +717,12 @@ PHPAPI int php_output_handler_hook(php_output_handler_hook_t type, void *arg TSR * Destroy an output handler */ PHPAPI void php_output_handler_dtor(php_output_handler *handler TSRMLS_DC) { -//??? STR_FREE(handler->name); - if (handler->name) efree(handler->name); -//??? STR_FREE(handler->buffer.data); - if (handler->buffer.data) efree(handler->buffer.data); + if (handler->name) { + STR_RELEASE(handler->name); + } + if (handler->buffer.data) { + efree(handler->buffer.data); + } if (handler->flags & PHP_OUTPUT_HANDLER_USER) { zval_ptr_dtor(&handler->func.user->zoh); efree(handler->func.user); @@ -876,13 +880,12 @@ static inline void php_output_context_dtor(php_output_context *context) /* {{{ static php_output_handler *php_output_handler_init(zval *name, size_t chunk_size, int flags TSRMLS_DC) * Allocates and initializes a php_output_handler structure */ -static inline php_output_handler *php_output_handler_init(const char *name, size_t name_len, size_t chunk_size, int flags TSRMLS_DC) +static inline php_output_handler *php_output_handler_init(zend_string *name, size_t chunk_size, int flags TSRMLS_DC) { php_output_handler *handler; handler = ecalloc(1, sizeof(php_output_handler)); - handler->name = estrndup(name, name_len); - handler->name_len = name_len; + handler->name = STR_COPY(name); handler->size = chunk_size; handler->flags = flags; handler->buffer.size = PHP_OUTPUT_HANDLER_INITBUF_SIZE(chunk_size); @@ -1169,7 +1172,7 @@ static int php_output_stack_apply_list(void *h, void *z) php_output_handler *handler = *(php_output_handler **) h; zval *array = (zval *) z; - add_next_index_stringl(array, handler->name, handler->name_len); + add_next_index_str(array, STR_COPY(handler->name)); return 0; } /* }}} */ @@ -1193,7 +1196,7 @@ static inline zval *php_output_handler_status(php_output_handler *handler, zval ZEND_ASSERT(entry != NULL); array_init(entry); - add_assoc_stringl(entry, "name", handler->name, handler->name_len); + add_assoc_str(entry, "name", STR_COPY(handler->name)); add_assoc_long(entry, "type", (long) (handler->flags & 0xf)); add_assoc_long(entry, "flags", (long) handler->flags); add_assoc_long(entry, "level", (long) handler->level); @@ -1219,7 +1222,7 @@ static inline int php_output_stack_pop(int flags TSRMLS_DC) return 0; } else if (!(flags & PHP_OUTPUT_POP_FORCE) && !(orphan->flags & PHP_OUTPUT_HANDLER_REMOVABLE)) { if (!(flags & PHP_OUTPUT_POP_SILENT)) { - php_error_docref("ref.outcontrol" TSRMLS_CC, E_NOTICE, "failed to %s buffer of %s (%d)", (flags&PHP_OUTPUT_POP_DISCARD)?"discard":"send", orphan->name, orphan->level); + php_error_docref("ref.outcontrol" TSRMLS_CC, E_NOTICE, "failed to %s buffer of %s (%d)", (flags&PHP_OUTPUT_POP_DISCARD)?"discard":"send", orphan->name->val, orphan->level); } return 0; } else { @@ -1346,7 +1349,7 @@ PHP_FUNCTION(ob_flush) } if (SUCCESS != php_output_flush(TSRMLS_C)) { - php_error_docref("ref.outcontrol" TSRMLS_CC, E_NOTICE, "failed to flush buffer of %s (%d)", OG(active)->name, OG(active)->level); + php_error_docref("ref.outcontrol" TSRMLS_CC, E_NOTICE, "failed to flush buffer of %s (%d)", OG(active)->name->val, OG(active)->level); RETURN_FALSE; } RETURN_TRUE; @@ -1367,7 +1370,7 @@ PHP_FUNCTION(ob_clean) } if (SUCCESS != php_output_clean(TSRMLS_C)) { - php_error_docref("ref.outcontrol" TSRMLS_CC, E_NOTICE, "failed to delete buffer of %s (%d)", OG(active)->name, OG(active)->level); + php_error_docref("ref.outcontrol" TSRMLS_CC, E_NOTICE, "failed to delete buffer of %s (%d)", OG(active)->name->val, OG(active)->level); RETURN_FALSE; } RETURN_TRUE; @@ -1422,7 +1425,7 @@ PHP_FUNCTION(ob_get_flush) } if (SUCCESS != php_output_end(TSRMLS_C)) { - php_error_docref("ref.outcontrol" TSRMLS_CC, E_NOTICE, "failed to delete buffer of %s (%d)", OG(active)->name, OG(active)->level); + php_error_docref("ref.outcontrol" TSRMLS_CC, E_NOTICE, "failed to delete buffer of %s (%d)", OG(active)->name->val, OG(active)->level); } } /* }}} */ @@ -1445,7 +1448,7 @@ PHP_FUNCTION(ob_get_clean) } if (SUCCESS != php_output_discard(TSRMLS_C)) { - php_error_docref("ref.outcontrol" TSRMLS_CC, E_NOTICE, "failed to delete buffer of %s (%d)", OG(active)->name, OG(active)->level); + php_error_docref("ref.outcontrol" TSRMLS_CC, E_NOTICE, "failed to delete buffer of %s (%d)", OG(active)->name->val, OG(active)->level); } } /* }}} */ diff --git a/main/php_output.h b/main/php_output.h index 45af14f6a5..f8b961c7c3 100644 --- a/main/php_output.h +++ b/main/php_output.h @@ -127,8 +127,7 @@ typedef struct _php_output_handler_user_func_t { } php_output_handler_user_func_t; typedef struct _php_output_handler { - char *name; - size_t name_len; + zend_string *name; int flags; int level; size_t size;