# Concern about changing zval's passed by reference

- Thread: https://externals.io/message/5731
- Original archive: https://news-web.php.net/php.internals/5731
- Started by Robert Twitty on 2003-11-26T22:32:48+00:00
- Messages: 2
- 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

---

## #5731 — Robert Twitty — 2003-11-26T22:32:48+00:00

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

Hello

I am using the macros ZVAL_BOOL, ZVAL_LONG, ZVAL_DOUBLE and ZVAL_STRING to
change the value of a zval passed by reference.  I noticed that these
macros do not free the original value if it's a string, array, object or
resource prior to the change.  This causes a possible memory leak.  Is
this a normal practice?  And, if not, what is the accepted practice for
changing zval's passed by reference?

-- bob

---

## #5732 — Marcus Boerger — 2003-11-26T23:10:28+00:00

URL: https://externals.io/message/5731#5732 · In reply to: #5731

Hello Robert,

Wednesday, November 26, 2003, 11:32:48 PM, you wrote:

> Hello

> I am using the macros ZVAL_BOOL, ZVAL_LONG, ZVAL_DOUBLE and ZVAL_STRING to
> change the value of a zval passed by reference.  I noticed that these
> macros do not free the original value if it's a string, array, object or
> resource prior to the change.  This causes a possible memory leak.  Is
> this a normal practice?  And, if not, what is the accepted practice for
> changing zval's passed by reference?

You need to free the value prior to overwriting it by zval_dtor() or you
need to use the appropriate zval change macro.

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