harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Pavel Pervov (JIRA)" <j...@apache.org>
Subject [jira] Commented: (HARMONY-5547) [drlvm] memory leaks in properties.cpp caused by incorrect usage of strdup with apr_hash_*
Date Wed, 27 Feb 2008 07:42:51 GMT

    [ https://issues.apache.org/jira/browse/HARMONY-5547?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12572815#action_12572815

Pavel Pervov commented on HARMONY-5547:


Do we really need dupping the key if that key already exists in the hash? You've just mentioned
that the key is dropped by APR in this case...

I think that we also can fold first 'if(val != NULL)' into '?:' type construct like:

key_dup = (val != NULL)? key : apr_pstrdup(local_ht_pool, key);

and move added comment right above this line.

> [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.

View raw message