You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@celix.apache.org by "Daniel Parker (JIRA)" <ji...@apache.org> on 2015/02/10 15:49:12 UTC
[jira] [Closed] (CELIX-218) Memory leaks in service_registry.c
[ https://issues.apache.org/jira/browse/CELIX-218?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Daniel Parker closed CELIX-218.
-------------------------------
Resolution: Fixed
Fixed as of REV 1658718
> 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(®istry->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(®istry->mutex);
> }
> // destroy all entries from registry->listenerHooks, then registry->listenerHooks itself
> if (registry->listenerHooks != NULL)
> {
> celixThreadMutex_lock(®istry->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(®istry->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(®istry->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(®istry->mutex);
> }
> // destroy all entries from registry->serviceReferences, then registry->serviceReferences itself
> if (registry->serviceReferences != NULL)
> {
> celixThreadMutex_lock(®istry->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(®istry->referencesMapMutex);
> }
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)