]> granicus.if.org Git - php/commitdiff
fixed memory leak
authorAnatol Belski <ab@php.net>
Thu, 21 Aug 2014 10:13:52 +0000 (12:13 +0200)
committerAnatol Belski <ab@php.net>
Thu, 21 Aug 2014 10:13:52 +0000 (12:13 +0200)
ext/standard/string.c

index e43ec7d036df1c7451aeef696fec08d96adcbaf4..d104ac2e6856e1ff6c761c67cd45b48ab72320c2 100644 (file)
@@ -872,7 +872,7 @@ PHP_FUNCTION(ltrim)
    Wraps buffer to selected number of characters using string break char */
 PHP_FUNCTION(wordwrap)
 {
-       zend_string *text, *breakchar;
+       zend_string *text, *breakchar = NULL, *breakchar_save = NULL;
        php_size_t newtextlen, chk;
        size_t alloced;
        php_int_t current = 0, laststart = 0, lastspace = 0;
@@ -880,12 +880,20 @@ PHP_FUNCTION(wordwrap)
        zend_bool docut = 0;
        zend_string *newtext;
 
-       breakchar = STR_INIT("\n", 1, 0);
+       breakchar = breakchar_save = STR_INIT("\n", 1, 1);
+       if (!breakchar) {
+               return;
+       }
 
        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "S|iSb", &text, &linelength, &breakchar, &docut) == FAILURE) {
+               STR_FREE(breakchar);
                return;
        }
 
+       if (breakchar != breakchar_save) {
+               STR_FREE(breakchar_save);
+       }
+
        if (text->len == 0) {
                RETURN_EMPTY_STRING();
        }