# Iterators and new destructors

- Thread: https://externals.io/message/7644
- Original archive: https://news-web.php.net/php.internals/7644
- Started by Rob Richards on 2004-02-08T16:39:53+00:00
- Messages: 3
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #7644 — Rob Richards — 2004-02-08T16:39:53+00:00

URL: https://externals.io/message/7644#7644

It appears that the zend iterators need to go back to using the dtor
callback rather than free storage.
throwing an unhandled exception in any of the iterator foreach loops in SPL,
SXE and DOM results in a segfault due to improper cleanup.

To reproduce, put a throw new exception within one of the foreach calls in
limititerator or array_iterator from the SPL tests.

Registering dtor instead of a free storage callback in zend_iterator_wrap
seems to let the iterator objects cleanup properly.
Also in zend_objects_store_del_ref, free_storage is never tested so if an
object doesn't implement this, it causes a segfault.

Patch attached.

Rob

---

## #7645 — Andi Gutmans — 2004-02-08T17:08:47+00:00

URL: https://externals.io/message/7644#7645 · In reply to: #7644

I submitted the patch for checking free_storage != NULL.
Marcus, will have to look into SPL and see if dtor is more suitable than 
free_storage.

Andi

At 11:39 AM 2/8/2004 -0500, Rob Richards wrote:
>It appears that the zend iterators need to go back to using the dtor
>callback rather than free storage.
>throwing an unhandled exception in any of the iterator foreach loops in SPL,
>SXE and DOM results in a segfault due to improper cleanup.
>
>To reproduce, put a throw new exception within one of the foreach calls in
>limititerator or array_iterator from the SPL tests.
>
>Registering dtor instead of a free storage callback in zend_iterator_wrap
>seems to let the iterator objects cleanup properly.
>Also in zend_objects_store_del_ref, free_storage is never tested so if an
>object doesn't implement this, it causes a segfault.
>
>Patch attached.
>
>Rob

---

## #7653 — Marcus Boerger — 2004-02-08T21:27:23+00:00

URL: https://externals.io/message/7644#7653 · In reply to: #7645

Hello Andi,

without looking at the code i guessed iterators needed both, destruction
and cleaning. But unfortunatley i fear i cannot look into it until
wednesday. So i took a few mins right now and i'd say you should commit
Rob's patch which seems correct.

regards
marcus

Sunday, February 8, 2004, 6:08:47 PM, you wrote:

> I submitted the patch for checking free_storage != NULL.
> Marcus, will have to look into SPL and see if dtor is more suitable than 
> free_storage.

> Andi

> At 11:39 AM 2/8/2004 -0500, Rob Richards wrote:
> > […]




-- 
Best regards,
 Marcus                            mailto:helly@php.net
