summaryrefslogtreecommitdiff
path: root/ext/standard/string.c
diff options
context:
space:
mode:
authorXinchen Hui <laruence@gmail.com>2014-03-06 19:00:51 +0800
committerXinchen Hui <laruence@gmail.com>2014-03-06 19:00:51 +0800
commit11166882c05d9d194c31d6fc320260922af9567c (patch)
treee070940e254858296dd8d9636a1ee83d8093c562 /ext/standard/string.c
parent9a81b6dea43be43c6062419d5bef361be511e78e (diff)
downloadphp-git-11166882c05d9d194c31d6fc320260922af9567c.tar.gz
Fixed memory leak in ext/standard/tests/strings/str_word_count.php
Diffstat (limited to 'ext/standard/string.c')
-rw-r--r--ext/standard/string.c14
1 files changed, 9 insertions, 5 deletions
diff --git a/ext/standard/string.c b/ext/standard/string.c
index 65522cc36f..c2acc16d14 100644
--- a/ext/standard/string.c
+++ b/ext/standard/string.c
@@ -5346,7 +5346,7 @@ PHP_FUNCTION(str_shuffle)
*/
PHP_FUNCTION(str_word_count)
{
- char *buf, *str, *char_list = NULL, *p, *e, *s, ch[256];
+ char c, *str, *char_list = NULL, *p, *e, *s, ch[256];
int str_len, char_list_len = 0, word_count = 0;
long type = 0;
@@ -5398,12 +5398,16 @@ PHP_FUNCTION(str_word_count)
switch (type)
{
case 1:
- buf = estrndup(s, (p-s));
- add_next_index_stringl(return_value, buf, (p-s), 0);
+ c = s[p - s];
+ s[p - s] = '\0';
+ add_next_index_stringl(return_value, s, p - s, 1);
+ s[p - s] = c;
break;
case 2:
- buf = estrndup(s, (p-s));
- add_index_stringl(return_value, (s - str), buf, p-s, 0);
+ c = s[p - s];
+ s[p - s] = '\0';
+ add_index_stringl(return_value, (s - str), s, p - s, 1);
+ s[p - s] = c;
break;
default:
word_count++;