Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:54916 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 73085 invoked from network); 25 Aug 2011 07:42:27 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 25 Aug 2011 07:42:27 -0000 Authentication-Results: pb1.pair.com header.from=flavius.as@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=flavius.as@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.161.42 as permitted sender) X-PHP-List-Original-Sender: flavius.as@gmail.com X-Host-Fingerprint: 209.85.161.42 mail-fx0-f42.google.com Received: from [209.85.161.42] ([209.85.161.42:46300] helo=mail-fx0-f42.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id D0/40-06524-1ECF55E4 for ; Thu, 25 Aug 2011 03:42:26 -0400 Received: by fxe23 with SMTP id 23so1618500fxe.29 for ; Thu, 25 Aug 2011 00:42:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=message-id:date:from:user-agent:mime-version:to:subject :content-type:content-transfer-encoding; bh=ExGgBwTTXCW828UCg4wdLo0YdwcAclGEdFMW4hepRMY=; b=dft0vC/3wM00aLliA2A6SjFeC0F/yCy+oqOzCnSnDI6CrWG8EgF+NQYT/ow5nrFTyz ShfKda44xYH+BsduIXmQLyy2Eg0WDQygqZoTAqtKzjcGgEtD+b0K1nKAYIWZlNefHR8T ODJ2bZhYHiBC3ZnPtRa5WF8JXFkmVZE8/+wHA= Received: by 10.223.5.155 with SMTP id 27mr8827885fav.90.1314258142721; Thu, 25 Aug 2011 00:42:22 -0700 (PDT) Received: from [192.168.2.3] (chello080109207086.1.graz.surfer.at [80.109.207.86]) by mx.google.com with ESMTPS id c4sm76942fac.35.2011.08.25.00.42.21 (version=SSLv3 cipher=OTHER); Thu, 25 Aug 2011 00:42:21 -0700 (PDT) Message-ID: <4E55FCCA.5000604@gmail.com> Date: Thu, 25 Aug 2011 09:42:02 +0200 User-Agent: I am harmful. Fear me please :-) Mnenhy/0.7.6.666 MIME-Version: 1.0 To: internals@lists.php.net Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Subject: Array as class member and refcounting From: flavius.as@gmail.com (Flavius Aspra) There is something that confuses me. Let there be a class member Foo::$bar, which has to be initialized as an empty array in the constructor. If I do that (via zend_update_property), its refcount is increased (from 1, which it gets after alloc + array_init, to 2). It is obvious why this happens, since from zend_update_property gets a variable from somone in the outside world, and so it is right to ++ it. But in this particular case, the array being initialized in the constructor, it does not need a refcount of 2, 1 is right, since it's used only by the object (yet). So I thought I will Z_DELREF_P() it. And it worked. Until I started valgrind, which was reporting: ==4538== Invalid read of size 4 ==4538== at 0x822D3C6: _zval_ptr_dtor (zend.h:385) ==4538== by 0x823C1FF: _zval_ptr_dtor_wrapper (zend_variables.c:189) ==4538== by 0x824E1A1: zend_hash_destroy (zend_hash.c:529) ==4538== by 0x826655A: zend_object_std_dtor (zend_objects.c:45) ==4538== by 0x8266A28: zend_objects_free_object_storage (zend_objects.c:126) ==4538== by 0x826C43D: zend_objects_store_del_ref_by_handle_ex (zend_objects_API.c:220) ==4538== by 0x826C0AC: zend_objects_store_del_ref (zend_objects_API.c:172) ==4538== by 0x823BD77: _zval_dtor_func (zend_variables.c:52) ==4538== by 0x822B99B: _zval_dtor (zend_variables.h:35) ==4538== by 0x822D463: _zval_ptr_dtor (zend_execute_API.c:443) ==4538== by 0x823C1FF: _zval_ptr_dtor_wrapper (zend_variables.c:189) ==4538== by 0x824E518: zend_hash_apply_deleter (zend_hash.c:614) ==4538== Address 0x44c1718 is 8 bytes inside a block of size 20 free'd So it looks like the ZE really needs the refcount to be 2. All other tests I've written work fine, no memleaks, no segfaults whatsoever. Still I am a little bit confused: WHY does it need it be higher than (from my understanding) it should be? Thanks, Flavius