From 029cd8a8829cd856a9d09f91336b017de9b85b4d Mon Sep 17 00:00:00 2001 From: Chuck Hagenbuch Date: Mon, 23 Apr 2001 21:58:44 +0000 Subject: [PATCH] Fix for bug 9908: check that the result of mail_sort is not 0 before trying to dereference the pointer. :) Also, free sort programs - this might have been a memory leak. --- ext/imap/php_imap.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/ext/imap/php_imap.c b/ext/imap/php_imap.c index 7778d6608f5..7fb8213b15c 100644 --- a/ext/imap/php_imap.c +++ b/ext/imap/php_imap.c @@ -2745,12 +2745,17 @@ PHP_FUNCTION(imap_sort) mypgm->next = NIL; slst = mail_sort(imap_le_struct->imap_stream, NIL, spg, mypgm, myargc >= 4 ? Z_LVAL_PP(flags) : NIL); - - array_init(return_value); - for (sl = slst; *sl; sl++) { - add_next_index_long(return_value, *sl); + if (spg) { + mail_free_searchpgm(&spg); + } + + array_init(return_value); + if (slst != NIL && slst != 0) { + for (sl = slst; *sl; sl++) { + add_next_index_long(return_value, *sl); + } + fs_give ((void **) &slst); } - fs_give ((void **) &slst); } /* }}} */ @@ -3547,14 +3552,14 @@ PHP_FUNCTION(imap_search) imap_le_struct = (pils *) zend_list_find(ind, &ind_type); if (!imap_le_struct || !IS_STREAM(ind_type)) { php_error(E_WARNING, "Unable to find stream pointer"); - efree(search_criteria); + efree(search_criteria); RETURN_FALSE; } IMAPG(imap_messages) = NIL; mail_search_full(imap_le_struct->imap_stream, NIL, mail_criteria(search_criteria), flags); if (IMAPG(imap_messages) == NIL) { - efree(search_criteria); + efree(search_criteria); RETURN_FALSE; } @@ -3565,7 +3570,7 @@ PHP_FUNCTION(imap_search) cur = cur->next; } mail_free_messagelist(&IMAPG(imap_messages)); - efree(search_criteria); + efree(search_criteria); } /* }}} */