harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Egor Pasko (JIRA)" <j...@apache.org>
Subject [jira] Created: (HARMONY-5547) [drlvm] memory leaks in properties.cpp caused by incorrect usage of strdup with apr_hash_*
Date Tue, 26 Feb 2008 23:56:52 GMT
[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.


Mime
View raw message