# [PATCH] ext/date tzinfo structure references

- Thread: https://externals.io/message/38857
- Original archive: https://news-web.php.net/php.internals/38857
- Started by Joe Orton on 2008-07-08T14:40:49+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

---

## #38857 — Joe Orton — 2008-07-08T14:40:49+00:00

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

The result of calling getTimezone() on a Date object results in a 
DateTimeZone object with a reference to the dateobj->time->tz_info 
object which may get later destroyed.

This can cause unexpected script behaviour or interpreter crashes, test 
case in attachment (1).

When I fixed this the obvious way, per attachment 3, by adding a clone, 
I wondered where the cloned tzinfo structures would get destroyed and I 
can't see anywhere.

After looking at this further - so far as I can tell, the duplication of 
the tzinfo structures throughout this code is not actually necessary; 
when the structures are created they are referenced from the global 
tzcache and will hence last "forever" anyway.  The structures are not 
changed anywhere either, again AFAICT; though they aren't treated as 
const so maybe I'm missing something there.

So simply copying pointers around would simplify the code, fix leaks and 
fix the bug as well.  That's attachment (2).

What do you think?

Regards, Joe

---

## #38858 — Derick Rethans — 2008-07-08T14:59:43+00:00

URL: https://externals.io/message/38857#38858 · In reply to: #38857

> The result of calling getTimezone() on a Date object results in a 
> DateTimeZone object with a reference to the dateobj->time->tz_info 
> object which may get later destroyed.
> 
> This can cause unexpected script behaviour or interpreter crashes, test 
> case in attachment (1).
> 
> When I fixed this the obvious way, per attachment 3, by adding a clone, 
> I wondered where the cloned tzinfo structures would get destroyed and I 
> can't see anywhere.
> 
> After looking at this further - so far as I can tell, the duplication of 
> the tzinfo structures throughout this code is not actually necessary; 
> when the structures are created they are referenced from the global 
> tzcache and will hence last "forever" anyway.  The structures are not 
> changed anywhere either, again AFAICT; though they aren't treated as 
> const so maybe I'm missing something there.
> 
> So simply copying pointers around would simplify the code, fix leaks and 
> fix the bug as well.  That's attachment (2).
> 
> What do you think?

Sounds sane... I was going to have a look at this tonight and do 
something similar - this saves some work. I'll see if it fixes all 
leaks, and commit it if it works fine. Thanks for the patch.

regards,
Derick

-- 
Derick Rethans
http://derickrethans.nl | http://ezcomponents.org | http://xdebug.org
