From ddd8d7f3efb6af9d46645ed999143a83d1a0eaed Mon Sep 17 00:00:00 2001 From: Antony Dovgal Date: Wed, 20 Dec 2006 23:30:11 +0000 Subject: [PATCH] do not allocate the return value if it wasn't requested --- ext/standard/string.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) 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) { -- 2.50.1