PengZheng commented on code in PR #729:
URL: https://github.com/apache/celix/pull/729#discussion_r1502550497


##########
libs/framework/src/bundle_context.c:
##########
@@ -699,26 +702,31 @@ static void 
bundleContext_cleanupBundleTrackers(bundle_context_t *ctx) {
     }
 }
 
-static void bundleContext_cleanupServiceTrackers(bundle_context_t *ctx) {
+static void bundleContext_cleanupServiceTrackers(bundle_context_t* ctx) {
     module_pt module;
-    const char *symbolicName;
+    const char* symbolicName;
     bundle_getCurrentModule(ctx->bundle, &module);
     module_getSymbolicName(module, &symbolicName);
 
     celix_array_list_t* danglingTrkIds = NULL;
 
-    celixThreadMutex_lock(&ctx->mutex);
-    hash_map_iterator_t iter = hashMapIterator_construct(ctx->serviceTrackers);
-    while (hashMapIterator_hasNext(&iter)) {
-        long trkId = (long)hashMapIterator_nextKey(&iter);
-        celix_bundle_context_service_tracker_entry_t* entry = 
hashMap_get(ctx->serviceTrackers, (void*)trkId);
-        fw_log(ctx->framework->logger, CELIX_LOG_LEVEL_ERROR, "Dangling 
service tracker with trkId %li, for bundle %s and with filter %s. Add missing 
'celix_bundleContext_stopTracker' calls.", trkId, symbolicName, 
entry->tracker->filter);
+    celixThreadRwlock_writeLock(&ctx->lock);
+    CELIX_LONG_HASH_MAP_ITERATE(ctx->serviceTrackers, iter) {
+        long trkId = iter.key;
+        celix_bundle_context_service_tracker_entry_t* entry = 
celix_longHashMap_get(ctx->serviceTrackers, trkId);
+        fw_log(ctx->framework->logger,
+               CELIX_LOG_LEVEL_ERROR,
+               "Dangling service tracker with trkId %li, for bundle %s and 
with filter %s. Add missing "
+               "'celix_bundleContext_stopTracker' calls.",
+               trkId,
+               symbolicName,
+               entry->tracker->filter);

Review Comment:
   Note that `entry->tracker` might be `nullptr`, which may lead to crash.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscr...@celix.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to