From 9feccc37fdc86040827fafa2829ae90b5265890c Mon Sep 17 00:00:00 2001 From: Reeze Xia Date: Thu, 21 Mar 2013 00:41:53 +0800 Subject: [PATCH] Fixed memory leak of SplDoublyLinkedList::add() when set invalid index This affected tests: ext/spl/tests/SplDoublyLinkedList_add_invalid_offset.phpt ext/spl/tests/SplDoublyLinkedList_add_null_offset.phpt ext/spl/tests/dllist_013.phpt --- ext/spl/spl_dllist.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ext/spl/spl_dllist.c b/ext/spl/spl_dllist.c index 83610863e42a3..552e43d0546ec 100644 --- a/ext/spl/spl_dllist.c +++ b/ext/spl/spl_dllist.c @@ -1246,7 +1246,6 @@ SPL_METHOD(SplDoublyLinkedList, add) if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zz", &zindex, &value) == FAILURE) { return; } - SEPARATE_ARG_IF_REF(value); intern = (spl_dllist_object*)zend_object_store_get_object(getThis() TSRMLS_CC); index = spl_offset_convert_to_long(zindex TSRMLS_CC); @@ -1256,6 +1255,8 @@ SPL_METHOD(SplDoublyLinkedList, add) return; } + SEPARATE_ARG_IF_REF(value); + if (index == intern->llist->count) { /* If index is the last entry+1 then we do a push because we're not inserting before any entry */ spl_ptr_llist_push(intern->llist, value TSRMLS_CC);