celix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From erjanalt...@apache.org
Subject celix git commit: CELIX-403: Free service-listener memory if tracker is closed to fix memory leak.
Date Thu, 23 Feb 2017 13:59:06 GMT
Repository: celix
Updated Branches:
  refs/heads/develop 8670cae69 -> 3b802c90f


CELIX-403: Free service-listener memory if tracker is closed to fix memory leak.


Project: http://git-wip-us.apache.org/repos/asf/celix/repo
Commit: http://git-wip-us.apache.org/repos/asf/celix/commit/3b802c90
Tree: http://git-wip-us.apache.org/repos/asf/celix/tree/3b802c90
Diff: http://git-wip-us.apache.org/repos/asf/celix/diff/3b802c90

Branch: refs/heads/develop
Commit: 3b802c90f1fc720b42ee28b052128724108d37d0
Parents: 8670cae
Author: Erjan Altena <erjan.altena@gmail.com>
Authored: Thu Feb 23 14:56:01 2017 +0100
Committer: Erjan Altena <erjan.altena@gmail.com>
Committed: Thu Feb 23 14:58:36 2017 +0100

----------------------------------------------------------------------
 .../private/src/activator.c                     | 21 ++++++++++++++++++++
 framework/private/src/service_tracker.c         |  5 ++++-
 2 files changed, 25 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/celix/blob/3b802c90/examples/service_hook_example/private/src/activator.c
----------------------------------------------------------------------
diff --git a/examples/service_hook_example/private/src/activator.c b/examples/service_hook_example/private/src/activator.c
index 77238aa..f2d2a15 100644
--- a/examples/service_hook_example/private/src/activator.c
+++ b/examples/service_hook_example/private/src/activator.c
@@ -24,6 +24,7 @@
  *  \copyright	Apache License, Version 2.0
  */
 #include <stdlib.h>
+#include <unistd.h>
 #include <stdio.h>
 
 #include "bundle_activator.h"
@@ -86,12 +87,32 @@ celix_status_t bundleActivator_start(void * handle, bundle_context_pt
context) {
     userData->hookService = hookService;
     userData->hookReg = NULL;
 
+    printf("Registering hook service\n");
+    bundleContext_registerService(context, OSGI_FRAMEWORK_LISTENER_HOOK_SERVICE_NAME, hookService,
NULL, &userData->hookReg);
+
+    printf("Unregistering hook service\n");
+    serviceRegistration_unregister(userData->hookReg);
+
+    printf("Re-Registering hook service\n");
+    userData->hookReg = NULL;
     bundleContext_registerService(context, OSGI_FRAMEWORK_LISTENER_HOOK_SERVICE_NAME, hookService,
NULL, &userData->hookReg);
 
     userData->trackerAfter = 0;
     serviceTracker_create(context, "MY_SERVICE_AFTER_REGISTERING_HOOK", NULL, &userData->trackerAfter);
     serviceTracker_open(userData->trackerAfter);
   
+    sleep(1);
+    printf("Closing tracker\n");
+    serviceTracker_close(userData->trackerAfter);
+    printf("Reopening tracker\n");
+    serviceTracker_open(userData->trackerAfter);
+    
+    sleep(1);
+    printf("Closing tracker\n");
+    serviceTracker_close(userData->trackerAfter);
+    printf("Reopening tracker\n");
+    serviceTracker_open(userData->trackerAfter);
+
 	return CELIX_SUCCESS;
 }
 

http://git-wip-us.apache.org/repos/asf/celix/blob/3b802c90/framework/private/src/service_tracker.c
----------------------------------------------------------------------
diff --git a/framework/private/src/service_tracker.c b/framework/private/src/service_tracker.c
index d43b362..2631058 100644
--- a/framework/private/src/service_tracker.c
+++ b/framework/private/src/service_tracker.c
@@ -166,8 +166,11 @@ celix_status_t serviceTracker_close(service_tracker_pt tracker) {
 	}
     if (status == CELIX_SUCCESS) {
         status = bundleContext_removeServiceListener(tracker->context, tracker->listener);
+        if(status == CELIX_SUCCESS) {
+            free(tracker->listener);
+            tracker->listener = NULL;
+        }
     }
-
 	framework_logIfError(logger, status, NULL, "Cannot close tracker");
 
 	return status;


Mime
View raw message