php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #59230 Order matters when calling unset() on surface and context variables
Submitted: 2010-05-25 09:13 UTC Modified: 2010-06-02 09:08 UTC
From: dave dot mulford at gmail dot com Assigned:
Status: Not a bug Package: cairo (PECL)
PHP Version: 5.2.10 OS: gentoo linux-2.6.30
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: dave dot mulford at gmail dot com
New email:
PHP Version: OS:

 

 [2010-05-25 09:13 UTC] dave dot mulford at gmail dot com
Description:
------------
Calling unset() on a surface and context variables in the incorrect order produces a memory leak. This is possibly a documentation bug?

Reproduce code:
---------------
Link to source. Lines 56 & 57 are the offending lines.
http://pastebin.com/cQyHWDuy



Expected result:
----------------
$ php cairo_poly_memleak_reproduce.php
Generating cairo polygon...[OK]
memory usage: 108936

Generating cairo polygon...[OK]
memory usage: 108936

Generating cairo polygon...[OK]
memory usage: 108936

Generating cairo polygon...[OK]
memory usage: 108936

Generating cairo polygon...[OK]
memory usage: 108936
^C

Actual result:
--------------
$ php cairo_poly_memleak_reproduce.php
Generating cairo polygon...[OK]
memory usage: 109208

Generating cairo polygon...[OK]
memory usage: 109480

Generating cairo polygon...[OK]
memory usage: 109752

Generating cairo polygon...[OK]
memory usage: 110024

Generating cairo polygon...[OK]
memory usage: 110296
^C

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-06-01 15:55 UTC] markskilbeck at gmail dot com
Congrats - you've discovered PHP 5.2's sucky Garbage 
Collection.

The issue is basically this: you have a surface and you have 
a context. Your context has a reference to said surface, and 
your surface a reference to said context, allowing you to 
get the context from the surface. When you destroy the 
context its ref-count is decremented. However, we still have 
a remaining reference to this context in the surface so the 
context isn't freed. When you then destroy the surface, it 
doesn't destroy the context, leaving a ref-count > 0 for the 
context zval. As such, the memory is never GC'd (freed by 
the Garbage Collector) and you have a memory leak.

This issue was fixed in 5.3

The documentation will be updated with a note on this 
behaviour.
 [2010-06-01 15:56 UTC] markskilbeck at gmail dot com
Some references: 

http://derickrethans.nl/circular-references.html
http://www.php.net/manual/en/features.gc.refcounting-
basics.php (last paragraph)
 [2010-06-02 07:35 UTC] markskilbeck@php.net
Thank you for taking the time to write to us, but this is not
a bug.

See above comments
 [2010-06-02 09:08 UTC] dave dot mulford at gmail dot com
Awesome. Thanks for the info. I've been trying to get our organization to switch to php-5.3 for some time now.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Dec 02 17:01:35 2024 UTC