This is an automated email from the ASF dual-hosted git repository.

pnoltes pushed a commit to branch feature/async_svc_registration
in repository https://gitbox.apache.org/repos/asf/celix.git


The following commit(s) were added to refs/heads/feature/async_svc_registration 
by this push:
     new 9a1c101  Fixes mem leak in findService(s)
9a1c101 is described below

commit 9a1c1016fdd80e880471ee619b422175db39ba1a
Author: Pepijn Noltes <[email protected]>
AuthorDate: Mon Oct 5 23:00:23 2020 +0200

    Fixes mem leak in findService(s)
---
 libs/framework/src/bundle_context.c   | 2 ++
 libs/framework/src/service_registry.c | 5 +++--
 2 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/libs/framework/src/bundle_context.c 
b/libs/framework/src/bundle_context.c
index 18b0af5..99e43e8 100644
--- a/libs/framework/src/bundle_context.c
+++ b/libs/framework/src/bundle_context.c
@@ -1359,6 +1359,7 @@ long 
celix_bundleContext_findServiceWithOptions(celix_bundle_context_t *ctx, con
         if (svcIds != NULL) {
             celix_arrayList_destroy(svcIds);
         }
+        free(filter);
     }
     return result;
 }
@@ -1375,6 +1376,7 @@ celix_array_list_t* 
celix_bundleContext_findServicesWithOptions(celix_bundle_con
     char* filter = 
celix_serviceRegistry_createFilterFor(ctx->framework->registry, 
opts->serviceName, opts->versionRange, opts->filter, opts->serviceLanguage, 
opts->ignoreServiceLanguage);
     if (filter != NULL) {
         result = celix_serviceRegisrty_findServices(ctx->framework->registry, 
filter);
+        free(filter);
     }
     return result;
 }
diff --git a/libs/framework/src/service_registry.c 
b/libs/framework/src/service_registry.c
index 43a052a..7f8c911 100644
--- a/libs/framework/src/service_registry.c
+++ b/libs/framework/src/service_registry.c
@@ -1037,12 +1037,13 @@ celix_array_list_t* celix_serviceRegisrty_findServices(
     }
 
     //sort matched registration and add the svc id to the result list.
-    celix_arrayList_sort(matchedRegistrations, 
celix_serviceRegistry_compareRegistrations);
+    if (celix_arrayList_size(matchedRegistrations) > 1) {
+        celix_arrayList_sort(matchedRegistrations, 
celix_serviceRegistry_compareRegistrations);
+    }
     for (int i = 0; i < celix_arrayList_size(matchedRegistrations); ++i) {
         service_registration_t* reg = 
celix_arrayList_get(matchedRegistrations, i);
         celix_arrayList_addLong(result, serviceRegistration_getServiceId(reg));
     }
-
     celixThreadRwlock_unlock(&registry->lock);
 
     celix_filter_destroy(filter);

Reply via email to