# bug in ext/zlib?

- Thread: https://externals.io/message/35317
- Original archive: https://news-web.php.net/php.internals/35317
- Started by Gregory Beaver on 2008-02-08T05:54:56+00:00
- Messages: 1
- 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

---

## #35317 — Gregory Beaver — 2008-02-08T05:54:56+00:00

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

Hi,

I'm having a terrible time removing a memory leak in pecl/phar that is
caused by a zval_dtor() call in zlib_filter.c.  I think the source of
the problem is that zlib_filter's creation function uses SEPARATE_ZVAL()
to separate from the passed in filter parameters.  Unfortunately, I
don't think this can work, because in many cases, the zval passed in
will not be separated (refcount is <= 1), and so the original zval is
freed, causing a double free.

I'm referring specifically to these lines:

http://lxr.php.net/source/php-src/ext/zlib/zlib_filter.c#368

Is there any reason not to switch out the SEPARATE_ZVAL() call to a
straightforward oldzval = tmpzval/ALLOC_ZVAL()/*tmpzval =
*oldzval/zval_copy_ctor(tmpzval)?  This would prevent any possibility of
modifying the original zval.

Greg
