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] Commented: (HARMONY-5547) [drlvm] memory leaks in properties.cpp caused by incorrect usage of strdup with apr_hash_*
Date Tue, 26 Feb 2008 23:58:51 GMT

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

Egor Pasko commented on HARMONY-5547:
-------------------------------------

P.S.: I did not investigate other strdups in the file, I suspect we need to review them as
well.

> [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,
0002-one-strdup-leak-fixed-by-allocating-only-new-keys.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