summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXinchen Hui <laruence@gmail.com>2014-02-25 13:08:16 +0800
committerXinchen Hui <laruence@gmail.com>2014-02-25 13:08:16 +0800
commitbfcb3defdda99345e42cfa2988f6312fdfc5b7ed (patch)
tree69c7abfec9ebbef7f00fb5de5d60a0dbfef88aba
parentf482092cabb82b688a8421ce5a2254e2f6aed5cf (diff)
downloadphp-git-bfcb3defdda99345e42cfa2988f6312fdfc5b7ed.tar.gz
Fixed memory leak in ext/standard/tests/strings/quotemeta_basic.php
-rw-r--r--ext/standard/string.c13
1 files changed, 7 insertions, 6 deletions
diff --git a/ext/standard/string.c b/ext/standard/string.c
index b54b18a4f6..3c6532d5f4 100644
--- a/ext/standard/string.c
+++ b/ext/standard/string.c
@@ -2557,11 +2557,12 @@ PHP_FUNCTION(substr_replace)
Quotes meta characters */
PHP_FUNCTION(quotemeta)
{
- char *str, *old;
+ char *old;
char *old_end;
char *p, *q;
char c;
int old_len;
+ zend_string *str;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &old, &old_len) == FAILURE) {
return;
@@ -2573,9 +2574,9 @@ PHP_FUNCTION(quotemeta)
RETURN_FALSE;
}
- str = safe_emalloc(2, old_len, 1);
+ str = STR_ALLOC(2 * old_len, 0);
- for (p = old, q = str; p != old_end; p++) {
+ for (p = old, q = str->val; p != old_end; p++) {
c = *p;
switch (c) {
case '.':
@@ -2595,10 +2596,10 @@ PHP_FUNCTION(quotemeta)
*q++ = c;
}
}
- *q = 0;
-//??? RETURN_STRINGL(erealloc(str, q - str + 1), q - str, 0);
- RETURN_STRINGL(erealloc(str, q - str + 1), q - str);
+ *q = '\0';
+
+ RETURN_STR(STR_REALLOC(str, q - str->val, 0));
}
/* }}} */