celix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Daniel Parker (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (CELIX-218) Memory leaks in service_registry.c
Date Wed, 11 Feb 2015 15:54:12 GMT

    [ https://issues.apache.org/jira/browse/CELIX-218?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14316401#comment-14316401
] 

Daniel Parker commented on CELIX-218:
-------------------------------------

Note: I'm testing this by starting celix (using valgrind) and then waiting for everything
to load, then running the command "stop 0" to exit.  This ought to cause everything to exit
cleanly.

The changes appear to have fixed the serviceRegistry_destroy() memory leaks.  I still think
that it would be a good idea for serviceRegistry_destroy() to check the lists it's supposed
to close to see if they have any data in them that needs to be dealt with.  But the primary
issue has been fixed.

> Memory leaks in service_registry.c
> ----------------------------------
>
>                 Key: CELIX-218
>                 URL: https://issues.apache.org/jira/browse/CELIX-218
>             Project: Celix
>          Issue Type: Bug
>            Reporter: Daniel Parker
>
> serviceRegistry_destroy() should destroy each of the items within the registry->inUseMap,
registry->listenerHooks, registry->serviceRegistrations, and registry->serviceReferences
lists before it destroys the lists themselves.
> Suggested code to use (checked with valgrind):
>     // destroy all entries from registry->inUseMap, then registry->inUseMap itself
>     if (registry->inUseMap != NULL)
>     {
>        celixThreadMutex_lock(&registry->mutex);
>        hash_map_iter = hashMapIterator_create(registry->inUseMap);
>        while (hashMapIterator_hasNext(hash_map_iter) )
>        {
>           array_list_ptr = hashMapIterator_nextValue(hash_map_iter);
>           array_list_iter = arrayListIterator_create(array_list_ptr);
>           while (arrayListIterator_hasNext(array_list_iter) )
>           {
>              free(arrayListIterator_next(array_list_iter) );
>           }
>           arrayListIterator_destroy(array_list_iter);
>           arrayList_destroy(array_list_ptr);
>        }
>        hashMapIterator_destroy(hash_map_iter);
>        hashMap_destroy(registry->inUseMap, false, false);
>        registry->inUseMap = NULL;
>        celixThreadMutex_unlock(&registry->mutex);
>     }
>     // destroy all entries from registry->listenerHooks, then registry->listenerHooks
itself
>     if (registry->listenerHooks != NULL)
>     {
>        celixThreadMutex_lock(&registry->mutex);
>        array_list_iter = arrayListIterator_create(registry->listenerHooks);
>        while (arrayListIterator_hasNext(array_list_iter) )
>        {
>           service_registration_pt registration_ptr = arrayListIterator_next(array_list_iter);
>           serviceRegistration_destroy(registration_ptr);
>        }
>        arrayListIterator_destroy(array_list_iter);
>        arrayList_destroy(registry->listenerHooks);
>        registry->listenerHooks = NULL;
>        celixThreadMutex_unlock(&registry->mutex);
>     }
>     // destroy all entries from registry->serviceRegistrations, then registry->serviceRegistrations
itself
>     // note that each of the registrations in the array lists have already been destroyed
with registry->listenerHooks
>     if (registry->serviceRegistrations != NULL)
>     {
>        celixThreadMutex_lock(&registry->mutex);
>        hash_map_iter = hashMapIterator_create(registry->serviceRegistrations);
>        while (hashMapIterator_hasNext(hash_map_iter) )
>        {
>           arrayList_destroy(hashMapIterator_nextValue(hash_map_iter) );
>        }
>        hashMapIterator_destroy(hash_map_iter);
>        hashMap_destroy(registry->serviceRegistrations, false, false);
>        registry->serviceRegistrations = NULL;
>        celixThreadMutex_unlock(&registry->mutex);
>     }
>     // destroy all entries from registry->serviceReferences, then registry->serviceReferences
itself
>     if (registry->serviceReferences != NULL)
>     {
>        celixThreadMutex_lock(&registry->referencesMapMutex);
>        hash_map_iter = hashMapIterator_create(registry->serviceReferences);
>        while (hashMapIterator_hasNext(hash_map_iter) )
>        {
>           array_list_ptr = hashMapIterator_nextValue(hash_map_iter);
>           array_list_iter = arrayListIterator_create(array_list_ptr);
>           while (arrayListIterator_hasNext(array_list_iter) )
>           {
>              service_reference_pt service_ptr = arrayListIterator_next(array_list_iter);
>              serviceReference_destroy(&service_ptr);
>           }
>           arrayListIterator_destroy(array_list_iter);
>           arrayList_destroy(array_list_ptr);
>        }
>        hashMapIterator_destroy(hash_map_iter);
>        hashMap_destroy(registry->serviceReferences, false, false);
>        registry->serviceReferences = NULL;
>        celixThreadMutex_unlock(&registry->referencesMapMutex);
>     }



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Mime
View raw message