Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:88647 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 66017 invoked from network); 2 Oct 2015 19:04:57 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 2 Oct 2015 19:04:57 -0000 Authentication-Results: pb1.pair.com smtp.mail=zardozrocks@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=zardozrocks@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.213.173 as permitted sender) X-PHP-List-Original-Sender: zardozrocks@gmail.com X-Host-Fingerprint: 209.85.213.173 mail-ig0-f173.google.com Received: from [209.85.213.173] ([209.85.213.173:33159] helo=mail-ig0-f173.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 38/5C-23989-855DE065 for ; Fri, 02 Oct 2015 15:04:57 -0400 Received: by igbkq10 with SMTP id kq10so25439314igb.0 for ; Fri, 02 Oct 2015 12:04:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:content-type; bh=t1U5GUtnWIEwU3yGEPYXQ6i8giTT2lBzGxesLm/P+EM=; b=gZ2cwNGvVWtPXdLgs7lV6pOqfXJfKOMhoOSqstVIqhepRSpKOo9+HjbbOQlIWs4+fF soQmrYh6a9KsVyiPiAvvh/IspKJ9QdkIiLG3JVd1m6C/KFpVdkfqFmJQBUx7+3fPl7+P /K90J9wfZXncynC9LVhpttzAxT6SrMA1KS/ClDU1tNb++PtRxjf/wwvbe6zloNsDG5LJ ioTNkDfseWEVOHiaO0kfy0Eq9uG9aFXGGl/x8UA2PPH09k3qe1WtCNweOzTH0lYR8YFM dFs5a4p1PDsj+kRc/nFAf3tu4xyUaYKnBsA5fB9kj0XOflJzS3nz/NpCK3Kq/1ATN5rZ /8jw== MIME-Version: 1.0 X-Received: by 10.50.152.33 with SMTP id uv1mr539023igb.7.1443812694063; Fri, 02 Oct 2015 12:04:54 -0700 (PDT) Received: by 10.107.31.148 with HTTP; Fri, 2 Oct 2015 12:04:54 -0700 (PDT) Date: Fri, 2 Oct 2015 12:04:54 -0700 Message-ID: To: internals Content-Type: multipart/alternative; boundary=089e0149522cc09954052123d6f5 Subject: amfext: a little weird behavior, a couple of memory leaks From: zardozrocks@gmail.com (j adams) --089e0149522cc09954052123d6f5 Content-Type: text/plain; charset=UTF-8 I'm making slow progress on an updated version of AMFEXT. Most of the encoding functionality is complete but I'm struggling a bit with the decoding functions because I need to return zvals and other objects. In particular, I'm getting some memory leak notifications and I'm also getting some weird behavior when I add values to a HashTable and retrieve them later. I'd very much appreciate some guidance. A code review would be awesome if anyone is willing. I've posted the extension's source on github at https://github.com/sneakyimp/amfext === Problem 1: I pass a *zval to one of my functions by reference and it gets pointed to a zval object representing a string. I was trying to check Z_TYPE_P(myzval)==IS_STRING and even though it is a string with a type value of 6, the check says otherwise, though. I'm baffled by this because my code looks just like examples I've seen in 'Extending and Embedding PHP.' Code: zval *assoc_key; MAKE_STD_ZVAL(assoc_key); amf_read_string(buf, buf_len, buf_cursor, assoc_key, flags, htComplexObjects, htObjectTypeTraits, htStrings TSRMLS_CC); // had to remove this check because it was failing on empty strings for some reason if (Z_TYPE_P(assoc_key) == IS_STRING) { // the baffling thing is it returns "String expected, but returned object type is 6" php_error_docref(NULL TSRMLS_CC, E_ERROR, "String expected, but returned object type is %d", (unsigned int)Z_TYPE_P(assoc_key)); } Here's a link to the source on github: https://github.com/sneakyimp/amfext/blob/master/amf.c#L1242 === Problem 2: Similar to the previous problem, but the issue is that string zval is retrieved from a HashTable and when it comes out, the type value is messed up value. Code: // make sure it's a string // WTF? Z_TYPE_P(strz) is never IS_STRING and Z_STRVAL_P returns messed up values // e.g., "ZVAL stored at index 0 is not a string, type=-30420640" if (Z_TYPE_P(strz) != IS_STRING) { php_error_docref(NULL TSRMLS_CC, E_ERROR, "ZVAL stored at index %d is not a string, type=%d\n", (unsigned int)str_index, Z_STRVAL_P(strz)); } Here's a link to the source on github: https://github.com/sneakyimp/amfext/blob/master/amf.c#L1300 === Problem 3: Memory leaks! I concocted this test PHP script for my amf_decode function. It retrieves a data file containing an amf3-serialized array: array("abc", "abc", "abc", "a" => 1, "b" => 2, "c" => 3) And then decodes it. The PHP script: int(1) ["b"]=> int(2) ["c"]=> int(3) [0]=> string(3) "abc" [1]=> string(3) "abc" [2]=> string(3) "abc" } [Fri Oct 2 12:00:21 2015] Script: '/home/jaith/src/php-5.5.29/ext/amf/jta/read_arr_test2.php' /home/jaith/src/php-5.5.29/ext/amf/amf.c(1324) : Freeing 0x7F30D2091080 (32 bytes), script=/home/jaith/src/php-5.5.29/ext/amf/jta/read_arr_test2.php Last leak repeated 3 times [Fri Oct 2 12:00:21 2015] Script: '/home/jaith/src/php-5.5.29/ext/amf/jta/read_arr_test2.php' /home/jaith/src/php-5.5.29/ext/amf/amf.c(1330) : Freeing 0x7F30D2091270 (2 bytes), script=/home/jaith/src/php-5.5.29/ext/amf/jta/read_arr_test2.php Last leak repeated 2 times [Fri Oct 2 12:00:21 2015] Script: '/home/jaith/src/php-5.5.29/ext/amf/jta/read_arr_test2.php' /home/jaith/src/php-5.5.29/ext/amf/amf.c(1325) : Freeing 0x7F30D20914F0 (2 bytes), script=/home/jaith/src/php-5.5.29/ext/amf/jta/read_arr_test2.php Last leak repeated 3 times [Fri Oct 2 12:00:21 2015] Script: '/home/jaith/src/php-5.5.29/ext/amf/jta/read_arr_test2.php' /home/jaith/src/php-5.5.29/ext/amf/amf.c(1238) : Freeing 0x7F30D2092348 (32 bytes), script=/home/jaith/src/php-5.5.29/ext/amf/jta/read_arr_test2.php [Fri Oct 2 12:00:21 2015] Script: '/home/jaith/src/php-5.5.29/ext/amf/jta/read_arr_test2.php' /home/jaith/src/php-5.5.29/ext/amf/amf.c(1333) : Freeing 0x7F30D2092AB8 (1 bytes), script=/home/jaith/src/php-5.5.29/ext/amf/jta/read_arr_test2.php === Total 13 memory leaks detected === --089e0149522cc09954052123d6f5--