com php-src: Fixed memory leak in nlbr: ext/standard/string.c

From: Date: Mon, 24 Feb 2014 09:40:18 +0000
Subject: com php-src: Fixed memory leak in nlbr: ext/standard/string.c
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-77940@lists.php.net to get a copy of this message
Commit: b5291556352ecd7a3675cbdfb133e0f7f49984a1 Author: Xinchen Hui <laruence@gmail.com> Mon, 24 Feb 2014 17:40:18 +0800 Parents: a9529b8ad3becd738787211d649fd96cb80f2885 Branches: phpng Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=b5291556352ecd7a3675cbdfb133e0f7f49984a1 Log: Fixed memory leak in nlbr Changed paths: M ext/standard/string.c Diff: diff --git a/ext/standard/string.c b/ext/standard/string.c index de06916..40618f8 100644 --- a/ext/standard/string.c +++ b/ext/standard/string.c @@ -4164,12 +4164,12 @@ PHP_FUNCTION(hebrevc) PHP_FUNCTION(nl2br) { /* in brief this inserts <br /> or <br> before matched regexp \n\r?|\r\n? */ - char *tmp, *str; - int new_length; - char *end, *target; + char *tmp, *str; + char *end, *target; int repl_cnt = 0; int str_len; zend_bool is_xhtml = 1; + zend_string *result; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|b", &str, &str_len, &is_xhtml) == FAILURE) { return; @@ -4203,8 +4203,8 @@ PHP_FUNCTION(nl2br) { size_t repl_len = is_xhtml ? (sizeof("<br />") - 1) : (sizeof("<br>") - 1); - new_length = str_len + repl_cnt * repl_len; - tmp = target = safe_emalloc(repl_cnt, repl_len, str_len + 1); + result = STR_ALLOC(repl_cnt * repl_len + str_len, 0); + target = result->val; } while (str < end) { @@ -4235,8 +4235,7 @@ PHP_FUNCTION(nl2br) *target = '\0'; -//??? RETURN_STRINGL(tmp, new_length, 0); - RETURN_STRINGL(tmp, new_length); + RETURN_STR(result); } /* }}} */

« previous php.cvs (#77940) next »