colder Sun Jan 20 12:51:33 2008 UTC
Modified files:
/php-src/ext/spl spl_dllist.c
/php-src/ext/spl/tests dllist_006.phpt
Log:
Fix mem errors
http://cvs.php.net/viewvc.cgi/php-src/ext/spl/spl_dllist.c?r1=1.3&r2=1.4&diff_format=u
Index: php-src/ext/spl/spl_dllist.c
diff -u php-src/ext/spl/spl_dllist.c:1.3 php-src/ext/spl/spl_dllist.c:1.4
--- php-src/ext/spl/spl_dllist.c:1.3 Tue Jan 15 15:45:44 2008
+++ php-src/ext/spl/spl_dllist.c Sun Jan 20 12:51:33 2008
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: spl_dllist.c,v 1.3 2008/01/15 15:45:44 rrichards Exp $ */
+/* $Id: spl_dllist.c,v 1.4 2008/01/20 12:51:33 colder Exp $ */
#ifdef HAVE_CONFIG_H
# include "config.h"
@@ -39,18 +39,12 @@
PHPAPI zend_class_entry *spl_ce_SplQueue;
PHPAPI zend_class_entry *spl_ce_SplStack;
-#define SPL_LLIST_DELREF(elem, dtor) if(!--(elem)->rc) { \
- if(dtor) { \
- dtor(elem); \
- } \
+#define SPL_LLIST_DELREF(elem) if(!--(elem)->rc) { \
efree(elem); \
elem = NULL; \
}
-#define SPL_LLIST_CHECK_DELREF(elem, dtor) if((elem) && !--(elem)->rc) { \
- if(dtor) { \
- dtor(elem); \
- } \
+#define SPL_LLIST_CHECK_DELREF(elem) if((elem) && !--(elem)->rc) { \
efree(elem); \
elem = NULL; \
}
@@ -113,7 +107,11 @@
/* {{{ spl_ptr_llist */
static void spl_ptr_llist_zval_dtor(spl_ptr_llist_element *elem) { /* {{{ */
- zval_ptr_dtor((zval **)&elem->data);
+ if (elem->data) {
+ zval_ptr_dtor((zval **)&elem->data);
+ elem->data = NULL;
+ }
+
}
/* }}} */
@@ -148,7 +146,10 @@
while (current) {
next = current->next;
- SPL_LLIST_DELREF(current, dtor);
+ if(current && dtor) {
+ dtor(current);
+ }
+ SPL_LLIST_DELREF(current);
current = next;
}
@@ -225,7 +226,6 @@
{
void *data;
spl_ptr_llist_element *tail = llist->tail;
- spl_ptr_llist_dtor_func dtor = NULL;
if (tail == NULL) {
return NULL;
@@ -240,8 +240,9 @@
llist->tail = tail->prev;
llist->count--;
data = tail->data;
+ tail->data = NULL;
- SPL_LLIST_DELREF(tail, dtor);
+ SPL_LLIST_DELREF(tail);
return data;
}
@@ -275,7 +276,6 @@
{
void *data;
spl_ptr_llist_element *head = llist->head;
- spl_ptr_llist_dtor_func dtor = NULL;
if (head == NULL) {
return NULL;
@@ -290,8 +290,9 @@
llist->head = head->next;
llist->count--;
data = head->data;
+ head->data = NULL;
- SPL_LLIST_DELREF(head, dtor);
+ SPL_LLIST_DELREF(head);
return data;
}
@@ -667,8 +668,7 @@
return Z_LVAL_P(offset);
}
}
- zend_throw_exception(spl_ce_OutOfRangeException, "Invalid offset", 0
TSRMLS_CC);
- return 0;
+ return -1;
}
/* }}} */
@@ -707,7 +707,7 @@
index = spl_dllist_offset_convert(zindex TSRMLS_CC);
if (index < 0 || index >= intern->llist->count) {
- zend_throw_exception(spl_ce_OutOfRangeException, "Offset out of
range", 0 TSRMLS_CC);
+ zend_throw_exception(spl_ce_OutOfRangeException, "Offset
invalid or out of range", 0 TSRMLS_CC);
return;
}
@@ -747,7 +747,7 @@
index = spl_dllist_offset_convert(zindex TSRMLS_CC);
if (index < 0 || index >= intern->llist->count) {
- zend_throw_exception(spl_ce_OutOfRangeException,
"Offset out of range", 0 TSRMLS_CC);
+ zend_throw_exception(spl_ce_OutOfRangeException,
"Offset invalid or out of range", 0 TSRMLS_CC);
return;
}
@@ -807,7 +807,11 @@
}
/* finally, delete the element */
llist->count--;
- SPL_LLIST_DELREF(element, llist->dtor);
+
+ if(llist->dtor) {
+ llist->dtor(element);
+ }
+ SPL_LLIST_DELREF(element);
} else {
zend_throw_exception(spl_ce_OutOfRangeException, "Offset
invalid", 0 TSRMLS_CC);
return;
@@ -818,7 +822,7 @@
{
spl_dllist_it *iterator = (spl_dllist_it *)iter;
- SPL_LLIST_CHECK_DELREF(iterator->traverse_pointer,
iterator->object->llist->dtor);
+ SPL_LLIST_CHECK_DELREF(iterator->traverse_pointer);
zend_user_it_invalidate_current(iter TSRMLS_CC);
zval_ptr_dtor((zval**)&iterator->intern.it.data);
@@ -841,7 +845,7 @@
spl_dllist_it *iterator = (spl_dllist_it *)iter;
spl_ptr_llist_element *element = iterator->traverse_pointer;
- if (element == NULL) {
+ if (element == NULL || element->data == NULL) {
*data = NULL;
} else {
*data = (zval **)&element->data;
@@ -872,17 +876,23 @@
iterator->traverse_pointer = old->prev;
iterator->traverse_position--;
if (iterator->flags & SPL_DLLIST_IT_DELETE) {
- spl_ptr_llist_pop(object->llist);
+ zval *prev = (zval
*)spl_ptr_llist_pop(object->llist);
+ if (prev) {
+ zval_ptr_dtor((zval **)&prev);
+ }
}
} else {
iterator->traverse_pointer = old->next;
iterator->traverse_position++;
if (iterator->flags & SPL_DLLIST_IT_DELETE) {
- spl_ptr_llist_shift(object->llist);
+ zval *prev = (zval
*)spl_ptr_llist_shift(object->llist);
+ if (prev) {
+ zval_ptr_dtor((zval **)&prev);
+ }
}
}
- SPL_LLIST_DELREF(old, object->llist->dtor);
+ SPL_LLIST_DELREF(old);
SPL_LLIST_CHECK_ADDREF(iterator->traverse_pointer);
}
}
@@ -894,7 +904,7 @@
spl_dllist_object *object = iterator->object;
spl_ptr_llist *llist = object->llist;
- SPL_LLIST_CHECK_DELREF(iterator->traverse_pointer, llist->dtor);
+ SPL_LLIST_CHECK_DELREF(iterator->traverse_pointer);
if (iterator->flags & SPL_DLLIST_IT_LIFO) {
iterator->traverse_position = llist->count-1;
iterator->traverse_pointer = llist->tail;
http://cvs.php.net/viewvc.cgi/php-src/ext/spl/tests/dllist_006.phpt?r1=1.1&r2=1.2&diff_format=u
Index: php-src/ext/spl/tests/dllist_006.phpt
diff -u php-src/ext/spl/tests/dllist_006.phpt:1.1
php-src/ext/spl/tests/dllist_006.phpt:1.2
--- php-src/ext/spl/tests/dllist_006.phpt:1.1 Tue Jan 15 09:37:50 2008
+++ php-src/ext/spl/tests/dllist_006.phpt Sun Jan 20 12:51:33 2008
@@ -58,7 +58,7 @@
int(3)
int(4)
int(2)
-Exception: Invalid offset
+Exception: Offset invalid or out of range
int(1)
-Exception: Offset out of range
+Exception: Offset invalid or out of range
===DONE===
--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php