From: Antony Dovgal Date: Wed, 20 Dec 2006 23:30:11 +0000 (+0000) Subject: do not allocate the return value if it wasn't requested X-Git-Tag: RELEASE_1_0_0RC1~595 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ddd8d7f3efb6af9d46645ed999143a83d1a0eaed;p=php do not allocate the return value if it wasn't requested --- diff --git a/ext/standard/string.c b/ext/standard/string.c index f60e739a4d..f51da3f5a9 100644 --- a/ext/standard/string.c +++ b/ext/standard/string.c @@ -1679,7 +1679,7 @@ PHP_FUNCTION(strtotitle) */ PHPAPI void php_u_basename(UChar *s, int len, UChar *suffix, int sufflen, UChar **p_ret, int *p_len TSRMLS_DC) { - UChar *ret = NULL, *end, *c, *comp, *cend; + UChar *end, *c, *comp, *cend; int state; c = comp = cend = s; @@ -1713,10 +1713,9 @@ PHPAPI void php_u_basename(UChar *s, int len, UChar *suffix, int sufflen, UChar } len = cend - comp; - ret = eustrndup(comp, len); if (p_ret) { - *p_ret = ret; + *p_ret = eustrndup(comp, len); } if (p_len) { *p_len = len; @@ -1784,11 +1783,10 @@ quit_loop: } len = cend - comp; - ret = emalloc(len + 1); - memcpy(ret, comp, len); - ret[len] = '\0'; - if (p_ret) { + ret = emalloc(len + 1); + memcpy(ret, comp, len); + ret[len] = '\0'; *p_ret = ret; } if (p_len) {