colder          Sun Jan 20 13:26:03 2008 UTC

  Modified files:              (Branch: PHP_5_3)
    /php-src/ext/spl    spl_dllist.c 
    /php-src/ext/spl/tests      dllist_006.phpt 
  Log:
  MFH: Fix mem errors
  
http://cvs.php.net/viewvc.cgi/php-src/ext/spl/spl_dllist.c?r1=1.1.2.4&r2=1.1.2.5&diff_format=u
Index: php-src/ext/spl/spl_dllist.c
diff -u php-src/ext/spl/spl_dllist.c:1.1.2.4 
php-src/ext/spl/spl_dllist.c:1.1.2.5
--- php-src/ext/spl/spl_dllist.c:1.1.2.4        Tue Jan 15 15:46:20 2008
+++ php-src/ext/spl/spl_dllist.c        Sun Jan 20 13:26:03 2008
@@ -16,7 +16,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: spl_dllist.c,v 1.1.2.4 2008/01/15 15:46:20 rrichards Exp $ */
+/* $Id: spl_dllist.c,v 1.1.2.5 2008/01/20 13:26:03 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;
 }
@@ -664,8 +665,7 @@
                        return Z_LVAL_P(offset);
                }
        }
-       zend_throw_exception(spl_ce_OutOfRangeException, "Invalid offset", 0 
TSRMLS_CC);
-       return 0;
+       return -1;
 } 
 /* }}} */
 
@@ -704,7 +704,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;
        }
 
@@ -744,7 +744,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;
                }
 
@@ -804,7 +804,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;
@@ -815,7 +819,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);
@@ -838,7 +842,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;
@@ -869,17 +873,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);
        }
 }
@@ -891,7 +901,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.2.2&r2=1.1.2.3&diff_format=u
Index: php-src/ext/spl/tests/dllist_006.phpt
diff -u php-src/ext/spl/tests/dllist_006.phpt:1.1.2.2 
php-src/ext/spl/tests/dllist_006.phpt:1.1.2.3
--- php-src/ext/spl/tests/dllist_006.phpt:1.1.2.2       Tue Jan 15 09:38:15 2008
+++ php-src/ext/spl/tests/dllist_006.phpt       Sun Jan 20 13:26:03 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

Reply via email to