]> granicus.if.org Git - php/commitdiff
- MFH: #47940, leaks in imap_body()
authorPierre Joye <pajoye@php.net>
Thu, 23 Apr 2009 22:32:41 +0000 (22:32 +0000)
committerPierre Joye <pajoye@php.net>
Thu, 23 Apr 2009 22:32:41 +0000 (22:32 +0000)
ext/imap/php_imap.c

index 7c9493efd8324e6ea6dcfa9521da5c5760a40c5e..ee829039ebfd37bf8ddad04fe988ffc1f902147e 100644 (file)
@@ -1219,6 +1219,8 @@ PHP_FUNCTION(imap_body)
        pils *imap_le_struct; 
        int msgindex, myargc=ZEND_NUM_ARGS();
        long flags=0L;
+       char *body;
+       unsigned long body_len = 0;
 
        if (myargc < 2 || myargc > 3 || zend_get_parameters_ex(myargc, &streamind, &msgno, &pflags) == FAILURE) {
                ZEND_WRONG_PARAM_COUNT();
@@ -1249,8 +1251,13 @@ PHP_FUNCTION(imap_body)
                php_error_docref(NULL TSRMLS_CC, E_WARNING, "Bad message number");
                RETURN_FALSE;
        }
-
-       RETVAL_STRING(mail_fetchtext_full (imap_le_struct->imap_stream, Z_LVAL_PP(msgno), NIL, myargc==3 ? Z_LVAL_PP(pflags) : NIL), 1);
+       body = mail_fetchtext_full (imap_le_struct->imap_stream, Z_LVAL_PP(msgno), NIL, (myargc==3 ? Z_LVAL_PP(pflags) : NIL));
+       if (body_len == 0) {
+               RETVAL_EMPTY_STRING();
+       } else {
+               RETVAL_STRINGL(body, body_len, 1);
+       }
+       free(body);
 }
 /* }}} */