From: Pierre Joye Date: Thu, 23 Apr 2009 22:32:41 +0000 (+0000) Subject: - MFH: #47940, leaks in imap_body() X-Git-Tag: php-5.2.10RC1~193 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8abacb029205a884d2721a00c414b8574903dc94;p=php - MFH: #47940, leaks in imap_body() --- diff --git a/ext/imap/php_imap.c b/ext/imap/php_imap.c index 7c9493efd8..ee829039eb 100644 --- a/ext/imap/php_imap.c +++ b/ext/imap/php_imap.c @@ -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); } /* }}} */