Return-Path: Delivered-To: apmail-harmony-commits-archive@www.apache.org Received: (qmail 98292 invoked from network); 26 Feb 2008 23:57:46 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 26 Feb 2008 23:57:46 -0000 Received: (qmail 34316 invoked by uid 500); 26 Feb 2008 23:57:41 -0000 Delivered-To: apmail-harmony-commits-archive@harmony.apache.org Received: (qmail 34298 invoked by uid 500); 26 Feb 2008 23:57:41 -0000 Mailing-List: contact commits-help@harmony.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@harmony.apache.org Delivered-To: mailing list commits@harmony.apache.org Received: (qmail 34289 invoked by uid 99); 26 Feb 2008 23:57:41 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 26 Feb 2008 15:57:41 -0800 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.140] (HELO brutus.apache.org) (140.211.11.140) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 26 Feb 2008 23:57:02 +0000 Received: from brutus (localhost [127.0.0.1]) by brutus.apache.org (Postfix) with ESMTP id 316B929A001A for ; Tue, 26 Feb 2008 15:56:52 -0800 (PST) Message-ID: <1192350780.1204070212201.JavaMail.jira@brutus> Date: Tue, 26 Feb 2008 15:56:52 -0800 (PST) From: "Egor Pasko (JIRA)" To: commits@harmony.apache.org Subject: [jira] Updated: (HARMONY-5547) [drlvm] memory leaks in properties.cpp caused by incorrect usage of strdup with apr_hash_* In-Reply-To: <875684969.1204070212172.JavaMail.jira@brutus> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Virus-Checked: Checked by ClamAV on apache.org [ https://issues.apache.org/jira/browse/HARMONY-5547?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ] Egor Pasko updated HARMONY-5547: -------------------------------- Attachment: 0001-one-strdup-leak-fixed-with-allocating-on-local_ht_pool.txt approach 1 attached: 0001-one-strdup-leak-fixed-with-allocating-on-local_ht_pool.txt > [drlvm] memory leaks in properties.cpp caused by incorrect usage of strdup with apr_hash_* > ------------------------------------------------------------------------------------------ > > Key: HARMONY-5547 > URL: https://issues.apache.org/jira/browse/HARMONY-5547 > Project: Harmony > Issue Type: Bug > Components: DRLVM > Environment: all, checked found on Linux/x86 > Reporter: Egor Pasko > Priority: Minor > Attachments: 0001-one-strdup-leak-fixed-with-allocating-on-local_ht_pool.txt > > > I noticed a memory leak during a simple Hello World in properties.cpp: > strdup() is duplicating a key for apr_hash_set(), but the duplicated memory is only used if there *is* actual insertion of the key. In case when the key is already in the hash, APR drops the pointer to key, but does not delete it. So, in this case duplicating the key leads to a memory leak. > Approaches: > 1. Obvious solution is to replace strdup(key) with apr_pstrdup(local_ht_pool, key), this preserves the leaky nature of the code and hides the actual leak. > 2. Alternative idea is to strdup(key), only if the key existed in the hash (and deleting the strdupped, of course), new keys get in with apr_pstrdup(local_ht_pool, key) > I prefer the second (although the code looks far less beautiful) -- This message is automatically generated by JIRA. - You can reply to this email to add a comment to the issue online.