Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:95011 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 21557 invoked from network); 10 Aug 2016 14:17:28 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 10 Aug 2016 14:17:28 -0000 Authentication-Results: pb1.pair.com header.from=cmbecker69@gmx.de; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=cmbecker69@gmx.de; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmx.de designates 212.227.17.21 as permitted sender) X-PHP-List-Original-Sender: cmbecker69@gmx.de X-Host-Fingerprint: 212.227.17.21 mout.gmx.net Received: from [212.227.17.21] ([212.227.17.21:60145] helo=mout.gmx.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 4B/43-05841-6773BA75 for ; Wed, 10 Aug 2016 10:17:26 -0400 Received: from [192.168.2.103] ([217.82.227.154]) by mail.gmx.com (mrgmx101) with ESMTPSA (Nemesis) id 0Ld4xA-1apauf30Vs-00iDcK; Wed, 10 Aug 2016 16:17:21 +0200 To: Nikita Popov References: Cc: PHP Internals List Message-ID: <9e9c440e-05d2-a452-556e-a6c62a9f195e@gmx.de> Date: Wed, 10 Aug 2016 16:17:23 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.2.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Provags-ID: V03:K0:ejE4rGPDhWLTT9LC44bKEmvVhO4jjWzzuI+QGh+7+uf/gz2MThO 1ewB2Nw9vttcHi6Fn2XlxMBUWfMX1Ppk6AH5l3SIDucofk+dRdy8V+hswi5aB7529wDUJx/ ayWm3SSXtbEV5gIa8NLnL/MO/G8djHaYJtK73rHZ4p41/7ZHlpCzFzN5BbKk/L8gBBDitUR PjD/P4DpEdMoeTAt8xMVQ== X-UI-Out-Filterresults: notjunk:1;V01:K0:JVRWFPqXKBw=:MVQ0pIlAVCO3FUQPW6MKDQ qKL3ZHkeLdo38OFmVL9+qD4mvEYgNQpVOzTwVxoxH/Jh/59euAOthb8GmZ2mztxhFJBKiP4kJ 8wyU4P7fjcMw60/5Ni7ln9f/clnc06yDAW8sVeCIFGzqAfLs+ZT8qTqSorfS/A0Pu0F42R2WD 4TF9WjX8C8Xwel8teE8J5ZoiRRCuHdp9VfeEAY9XeU9SPJNHokReirB1Jq9K0a5cJP4fIx9YO a6YhGWyGCtsCttA3nlXsc1HhGkVEnILQ0vZpLpJ8pyXUSqbcUyrWjT+QE4cJjUOh0lVCzQmgm FIVkrDohZrvJWiFkSkCzE0HBFG7qq46ATSJu4wo8utdYUQCZXymoFFqZHe3PS646WMy26aCNc yCZ+cmr6RaaPcZvXV9tb8k2rjyNOD41m1xUzWwiJuJrxiCovC92yA1bzP6zi9P7dCQO228Lvc ltQH4Z/qJ43P5A4Nr18Nq4wXOKvvt6jE6E9vHtem0txKIbuyUI8qPEAjPwimvxHeY8B0eF94G B5zno3gz08GJfWAOTQGedkfChIqqaz0RET2IMHXy3ToCt0ehtmI9UoPVge+2bZCNr3tbejBnC iR59Y7MphgaCVjenDFNGaxQgXwJAqZ6INc6YcFjmX5Fsk4EaMnFnIDiOHa4M3OJej1c+6gJAi 0Tdci5ub49C5y8l4XWqe/kpXxxfREc98S5fNv+x27sTQZmn9gATMWhyLakXfSMiMMDtUOMhsW tKmojB11WPo5J/jSXcRybTASb5yXIpLAePGnN/Pv2fph0WTWDO88iQlna6J841QEYxBJdt18g zUB2RQh Subject: Re: [PHP-DEV] GC issue wrt. to resource <-> object cycles? From: cmbecker69@gmx.de ("Christoph M. Becker") On 10.08.2016 at 12:59, Nikita Popov wrote: > On Wed, Aug 10, 2016 at 12:52 PM, Christoph M. Becker > wrote: >> >> I've tried to fix , and it looks like >> there's a general GC issue wrt. to resources referencing objects and >> vice versa. Aren't resource ZVALS put in the root buffer? >> >> See , which demonstrates the issue better than >> the test script in the bug report. A steady increase of allocated >> memory can be seen, even though gc_collect_cycles() is called. When >> uncommenting `unset($this->parser);`, everything is fine (the GC >> wouldn't be involved at all in this case). >> >> Wrt. to the PHP 5.6 behavior: this appears fine, but actually it's in >> error, because of . Not >> increasing the refcount of `parser->object` might theoretically lead to >> use-after-free scenarios. > > As you correctly deduced, we currently do not support GC for resources. > This would require introducing something akin to the get_gc handler for > resources. Thanks for the clarification! > The simplest way to fix ext/xml in particular is probably to migrate it to > use an object instead of a resource. I guess that is the best action in the long run (i.e. 7.2+), but that would of course cause a BC break, so probably it's best to document that the user has to break the cycle manually, if xml_set_object() is used (7.0, 7.1). Wrt. to PHP 5.6 it appears there are no issues at all. While the code out-commented by Thies is still there (which should be removed to avoid further confusion), in the following a (shallow) copy of the object is made, and apparently due to the additional refcount in the object store of PHP 5, everything is okay. Another alternative for PHP 7.2 might be to drop (after deprecation) xml_set_object(); actually, it seems to me this function is a relict of pre PHP 5. Cf. example #1[1]. Instead of doing: xml_set_object($this->parser, $this); xml_set_element_handler($this->parser, "tag_open", "tag_close"); one could simply do: xml_set_element_handler($this->parser, [$this, "tag_open"], [$this, "tag_close]); [1] -- Christoph M. Becker