Return-Path: X-Original-To: apmail-celix-commits-archive@www.apache.org Delivered-To: apmail-celix-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 889E61867D for ; Tue, 24 Nov 2015 18:26:58 +0000 (UTC) Received: (qmail 96526 invoked by uid 500); 24 Nov 2015 18:26:58 -0000 Delivered-To: apmail-celix-commits-archive@celix.apache.org Received: (qmail 96499 invoked by uid 500); 24 Nov 2015 18:26:58 -0000 Mailing-List: contact commits-help@celix.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@celix.apache.org Delivered-To: mailing list commits@celix.apache.org Received: (qmail 96490 invoked by uid 99); 24 Nov 2015 18:26:58 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 24 Nov 2015 18:26:58 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 46F68DFFEF; Tue, 24 Nov 2015 18:26:58 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: bpetri@apache.org To: commits@celix.apache.org Message-Id: <04a2597cb11d41778b0e5f47959bd74a@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: celix git commit: CELIX-305: Memory leaks in RSA_SHM, RSA_DFI, RSA_HTTP Date: Tue, 24 Nov 2015 18:26:58 +0000 (UTC) Repository: celix Updated Branches: refs/heads/develop d3c783c98 -> 52528fdc3 CELIX-305: Memory leaks in RSA_SHM, RSA_DFI, RSA_HTTP Project: http://git-wip-us.apache.org/repos/asf/celix/repo Commit: http://git-wip-us.apache.org/repos/asf/celix/commit/52528fdc Tree: http://git-wip-us.apache.org/repos/asf/celix/tree/52528fdc Diff: http://git-wip-us.apache.org/repos/asf/celix/diff/52528fdc Branch: refs/heads/develop Commit: 52528fdc30a80211ae2babf5247bf1250881dfe5 Parents: d3c783c Author: Bjoern Petri Authored: Tue Nov 24 19:25:01 2015 +0100 Committer: Bjoern Petri Committed: Tue Nov 24 19:25:01 2015 +0100 ---------------------------------------------------------------------- .../rsa/private/src/import_registration_dfi.c | 5 ++++- .../rsa/private/src/remote_service_admin_dfi.c | 16 +++++++++++++--- .../rsa_tst/rsa_client_server_tests.cpp | 19 ++++++++++++------- .../rsa_tst/rsa_tests.cpp | 7 +++++++ .../private/src/remote_service_admin_impl.c | 12 ++++++++---- .../private/test/rsa_client_server_tests.cpp | 10 ++++++++-- .../private/src/remote_service_admin_impl.c | 16 ++++++++++++++-- .../private/test/rsa_client_server_tests.cpp | 15 +++++++++++---- .../private/src/topology_manager.c | 4 ++++ 9 files changed, 81 insertions(+), 23 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/celix/blob/52528fdc/remote_services/remote_service_admin_dfi/rsa/private/src/import_registration_dfi.c ---------------------------------------------------------------------- diff --git a/remote_services/remote_service_admin_dfi/rsa/private/src/import_registration_dfi.c b/remote_services/remote_service_admin_dfi/rsa/private/src/import_registration_dfi.c index 99c49b6..813d75f 100644 --- a/remote_services/remote_service_admin_dfi/rsa/private/src/import_registration_dfi.c +++ b/remote_services/remote_service_admin_dfi/rsa/private/src/import_registration_dfi.c @@ -188,7 +188,7 @@ celix_status_t importRegistration_getService(import_registration_pt import, bund } static celix_status_t importRegistration_createProxy(import_registration_pt import, bundle_pt bundle, struct service_proxy **out) { - celix_status_t status = CELIX_SUCCESS; + celix_status_t status; char *descriptorFile = NULL; char name[128]; @@ -299,6 +299,9 @@ static void importRegistration_proxyFunc(void *userData, void *args[], void *ret } *(int *) returnVal = rc; + + free(invokeRequest); //Allocated by json_dumps in jsonRpc_prepareInvokeRequest + free(reply); //Allocated by json_dumps in remoteServiceAdmin_send through curl call } if (status != CELIX_SUCCESS) { http://git-wip-us.apache.org/repos/asf/celix/blob/52528fdc/remote_services/remote_service_admin_dfi/rsa/private/src/remote_service_admin_dfi.c ---------------------------------------------------------------------- diff --git a/remote_services/remote_service_admin_dfi/rsa/private/src/remote_service_admin_dfi.c b/remote_services/remote_service_admin_dfi/rsa/private/src/remote_service_admin_dfi.c index 67f6b30..a51795b 100644 --- a/remote_services/remote_service_admin_dfi/rsa/private/src/remote_service_admin_dfi.c +++ b/remote_services/remote_service_admin_dfi/rsa/private/src/remote_service_admin_dfi.c @@ -247,8 +247,10 @@ celix_status_t remoteServiceAdmin_stop(remote_service_admin_pt admin) { export_registration_pt export = arrayList_get(exports, i); if (export != NULL) { exportRegistration_stop(export); + exportRegistration_destroy(export); } } + arrayList_destroy(exports); } hashMapIterator_destroy(iter); celixThreadMutex_unlock(&admin->exportedServicesLock); @@ -260,6 +262,7 @@ celix_status_t remoteServiceAdmin_stop(remote_service_admin_pt admin) { import_registration_pt import = arrayList_get(admin->importedServices, i); if (import != NULL) { importRegistration_stop(import); + importRegistration_destroy(import); } } celixThreadMutex_unlock(&admin->importedServicesLock); @@ -371,7 +374,7 @@ static int remoteServiceAdmin_callback(struct mg_connection *conn) { } celix_status_t remoteServiceAdmin_exportService(remote_service_admin_pt admin, char *serviceId, properties_pt properties, array_list_pt *registrations) { - celix_status_t status = CELIX_SUCCESS; + celix_status_t status; arrayList_create(registrations); array_list_pt references = NULL; @@ -436,12 +439,16 @@ celix_status_t remoteServiceAdmin_exportService(remote_service_admin_pt admin, c hashMap_put(admin->exportedServices, reference, *registrations); celixThreadMutex_unlock(&admin->exportedServicesLock); } + else{ + arrayList_destroy(*registrations); + *registrations = NULL; + } return status; } celix_status_t remoteServiceAdmin_removeExportedService(remote_service_admin_pt admin, export_registration_pt registration) { - celix_status_t status = CELIX_SUCCESS; + celix_status_t status; logHelper_log(admin->loghelper, OSGI_LOGSERVICE_INFO, "RSA_DFI: Removing exported service"); @@ -453,7 +460,10 @@ celix_status_t remoteServiceAdmin_removeExportedService(remote_service_admin_pt celixThreadMutex_lock(&admin->exportedServicesLock); exportReference_getExportedService(ref, &servRef); - hashMap_remove(admin->exportedServices, servRef); + array_list_pt exports = (array_list_pt)hashMap_remove(admin->exportedServices, servRef); + if(exports!=NULL){ + arrayList_destroy(exports); + } exportRegistration_close(registration); exportRegistration_destroy(registration); http://git-wip-us.apache.org/repos/asf/celix/blob/52528fdc/remote_services/remote_service_admin_dfi/rsa_tst/rsa_client_server_tests.cpp ---------------------------------------------------------------------- diff --git a/remote_services/remote_service_admin_dfi/rsa_tst/rsa_client_server_tests.cpp b/remote_services/remote_service_admin_dfi/rsa_tst/rsa_client_server_tests.cpp index b4775f7..d091746 100644 --- a/remote_services/remote_service_admin_dfi/rsa_tst/rsa_client_server_tests.cpp +++ b/remote_services/remote_service_admin_dfi/rsa_tst/rsa_client_server_tests.cpp @@ -88,22 +88,27 @@ extern "C" { } static void test1(void) { - int rc = 0; + celix_status_t rc; service_reference_pt ref = NULL; tst_service_pt tst = NULL; + int retries = 4; - usleep(2000000); //TODO use tracker + while (ref == NULL && retries > 0) { + printf("Waiting for service .. %d\n", retries); + rc = bundleContext_getServiceReference(clientContext, (char *) TST_SERVICE_NAME, &ref); + usleep(1000000); + --retries; + } - bundleContext_getServiceReference(clientContext, (char *)TST_SERVICE_NAME, &ref); - CHECK_EQUAL(0, rc); + CHECK_EQUAL(CELIX_SUCCESS, rc); CHECK(ref != NULL); - bundleContext_getService(clientContext, ref, (void **)&tst); - CHECK_EQUAL(0, rc); + rc = bundleContext_getService(clientContext, ref, (void **)&tst); + CHECK_EQUAL(CELIX_SUCCESS, rc); CHECK(tst != NULL); rc = tst->test(tst->handle); - CHECK_EQUAL(0, rc); + CHECK_EQUAL(CELIX_SUCCESS, rc); bool result; bundleContext_ungetService(clientContext, ref, &result); http://git-wip-us.apache.org/repos/asf/celix/blob/52528fdc/remote_services/remote_service_admin_dfi/rsa_tst/rsa_tests.cpp ---------------------------------------------------------------------- diff --git a/remote_services/remote_service_admin_dfi/rsa_tst/rsa_tests.cpp b/remote_services/remote_service_admin_dfi/rsa_tst/rsa_tests.cpp index 3c64f95..d733909 100644 --- a/remote_services/remote_service_admin_dfi/rsa_tst/rsa_tests.cpp +++ b/remote_services/remote_service_admin_dfi/rsa_tst/rsa_tests.cpp @@ -136,6 +136,10 @@ extern "C" { CHECK_EQUAL(CELIX_SUCCESS, rc); CHECK_EQUAL(1, arrayList_size(regs)); + + rc = rsa->exportRegistration_close(rsa->admin,(export_registration_pt)(arrayList_get(regs,0))); + CHECK_EQUAL(CELIX_SUCCESS, rc); + } static void testImportService(void) { @@ -164,6 +168,9 @@ extern "C" { rc = bundleContext_ungetServiceReference(context, ref); CHECK_EQUAL(CELIX_SUCCESS, rc); + rc = endpointDescription_destroy(endpoint); + CHECK_EQUAL(CELIX_SUCCESS, rc); + /* Cannot test. uses requesting bundles descriptor void *service = NULL; rc = bundleContext_getService(context, ref, &service); http://git-wip-us.apache.org/repos/asf/celix/blob/52528fdc/remote_services/remote_service_admin_http/private/src/remote_service_admin_impl.c ---------------------------------------------------------------------- diff --git a/remote_services/remote_service_admin_http/private/src/remote_service_admin_impl.c b/remote_services/remote_service_admin_http/private/src/remote_service_admin_impl.c index 8567e23..2420fed 100644 --- a/remote_services/remote_service_admin_http/private/src/remote_service_admin_impl.c +++ b/remote_services/remote_service_admin_http/private/src/remote_service_admin_impl.c @@ -460,11 +460,11 @@ celix_status_t remoteServiceAdmin_exportService(remote_service_admin_pt admin, c } celix_status_t remoteServiceAdmin_removeExportedService(remote_service_admin_pt admin, export_registration_pt registration) { - celix_status_t status = CELIX_SUCCESS; + celix_status_t status; + export_reference_pt ref = NULL; logHelper_log(admin->loghelper, OSGI_LOGSERVICE_INFO, "RSA_HTTP: Removing exported service"); - export_reference_pt ref = NULL; status = exportRegistration_getExportReference(registration, &ref); if (status == CELIX_SUCCESS) { @@ -472,7 +472,10 @@ celix_status_t remoteServiceAdmin_removeExportedService(remote_service_admin_pt celixThreadMutex_lock(&admin->exportedServicesLock); exportReference_getExportedService(ref, &servRef); - hashMap_remove(admin->exportedServices, servRef); + array_list_pt registrations = (array_list_pt)hashMap_remove(admin->exportedServices, servRef); + if(registrations!=NULL){ + arrayList_destroy(registrations); + } exportRegistration_close(registration); exportRegistration_destroy(®istration); @@ -550,12 +553,13 @@ static celix_status_t remoteServiceAdmin_getIpAdress(char* interface, char** ip) celix_status_t status = CELIX_BUNDLE_EXCEPTION; struct ifaddrs *ifaddr, *ifa; - char host[NI_MAXHOST]; if (getifaddrs(&ifaddr) != -1) { for (ifa = ifaddr; ifa != NULL && status != CELIX_SUCCESS; ifa = ifa->ifa_next) { + char host[NI_MAXHOST]; + if (ifa->ifa_addr == NULL) continue; http://git-wip-us.apache.org/repos/asf/celix/blob/52528fdc/remote_services/remote_service_admin_http/private/test/rsa_client_server_tests.cpp ---------------------------------------------------------------------- diff --git a/remote_services/remote_service_admin_http/private/test/rsa_client_server_tests.cpp b/remote_services/remote_service_admin_http/private/test/rsa_client_server_tests.cpp index a2a087a..5c88b99 100644 --- a/remote_services/remote_service_admin_http/private/test/rsa_client_server_tests.cpp +++ b/remote_services/remote_service_admin_http/private/test/rsa_client_server_tests.cpp @@ -96,9 +96,15 @@ extern "C" { celix_status_t status; service_reference_pt ref = NULL; calculator_service_pt calcService = NULL; - usleep(2000000); //TODO use tracker + int retries = 4; + + while (ref == NULL && retries > 0) { + printf("Waiting for service .. %d\n", retries); + status = bundleContext_getServiceReference(clientContext, (char *) CALCULATOR_SERVICE, &ref); + usleep(1000000); + --retries; + } - status = bundleContext_getServiceReference(clientContext, (char *) CALCULATOR_SERVICE, &ref); CHECK_EQUAL(CELIX_SUCCESS, status); CHECK(ref != NULL); http://git-wip-us.apache.org/repos/asf/celix/blob/52528fdc/remote_services/remote_service_admin_shm/private/src/remote_service_admin_impl.c ---------------------------------------------------------------------- diff --git a/remote_services/remote_service_admin_shm/private/src/remote_service_admin_impl.c b/remote_services/remote_service_admin_shm/private/src/remote_service_admin_impl.c index 813fa19..adcfe91 100644 --- a/remote_services/remote_service_admin_shm/private/src/remote_service_admin_impl.c +++ b/remote_services/remote_service_admin_shm/private/src/remote_service_admin_impl.c @@ -553,7 +553,7 @@ celix_status_t remoteServiceAdmin_exportService(remote_service_admin_pt admin, c } celix_status_t remoteServiceAdmin_removeExportedService(remote_service_admin_pt admin, export_registration_pt registration) { - celix_status_t status = CELIX_SUCCESS; + celix_status_t status; ipc_segment_pt ipc = NULL; export_reference_pt ref = NULL; @@ -566,7 +566,10 @@ celix_status_t remoteServiceAdmin_removeExportedService(remote_service_admin_pt celixThreadMutex_lock(&admin->exportedServicesLock); exportReference_getExportedService(ref, &servRef); - hashMap_remove(admin->exportedServices, servRef); + array_list_pt exports = (array_list_pt)hashMap_remove(admin->exportedServices, servRef); + if(exports!=NULL){ + arrayList_destroy(exports); + } exportRegistration_close(registration); @@ -601,6 +604,10 @@ celix_status_t remoteServiceAdmin_removeExportedService(remote_service_admin_pt exportRegistration_destroy(®istration); } + if(ref!=NULL){ + free(ref); + } + celixThreadMutex_unlock(&admin->exportedServicesLock); return status; @@ -863,6 +870,11 @@ celix_status_t remoteServiceAdmin_removeImportedService(remote_service_admin_pt logHelper_log(admin->loghelper, OSGI_LOGSERVICE_ERROR, "Error while detaching IPC segment for imported service %s.", endpointDescription->service); } + ipc = hashMap_remove(admin->importedIpcSegment,endpointDescription); + if(ipc!=NULL){ + free(ipc); + } + // factory available if ((registration_factory == NULL) || (registration_factory->trackedFactory == NULL)) { logHelper_log(admin->loghelper, OSGI_LOGSERVICE_ERROR, "Error while retrieving registration factory for imported service %s.", endpointDescription->service); http://git-wip-us.apache.org/repos/asf/celix/blob/52528fdc/remote_services/remote_service_admin_shm/private/test/rsa_client_server_tests.cpp ---------------------------------------------------------------------- diff --git a/remote_services/remote_service_admin_shm/private/test/rsa_client_server_tests.cpp b/remote_services/remote_service_admin_shm/private/test/rsa_client_server_tests.cpp index b2ebb39..102c0b1 100644 --- a/remote_services/remote_service_admin_shm/private/test/rsa_client_server_tests.cpp +++ b/remote_services/remote_service_admin_shm/private/test/rsa_client_server_tests.cpp @@ -95,9 +95,16 @@ extern "C" { celix_status_t status; service_reference_pt ref = NULL; calculator_service_pt calcService = NULL; - usleep(2000000); //TODO use tracker + int retries = 6; + + while (ref == NULL && retries > 0) { + printf("Waiting for service .. %d\n", retries); + status = bundleContext_getServiceReference(clientContext, (char *) CALCULATOR_SERVICE, &ref); + usleep(1000000); + --retries; + } + - status = bundleContext_getServiceReference(clientContext, (char *) CALCULATOR_SERVICE, &ref); CHECK_EQUAL(CELIX_SUCCESS, status); CHECK(ref != NULL); @@ -463,9 +470,9 @@ TEST(RsaShmClientServerTests, TestImport) { } TEST(RsaShmClientServerTests, TestExport) { - // test is currenlty failing - //testExport(); + testExport(); } + /* TEST(RsaShmClientServerTests, TestProxyRemoval) { // test is currenlty failing http://git-wip-us.apache.org/repos/asf/celix/blob/52528fdc/remote_services/topology_manager/private/src/topology_manager.c ---------------------------------------------------------------------- diff --git a/remote_services/topology_manager/private/src/topology_manager.c b/remote_services/topology_manager/private/src/topology_manager.c index 46a3146..cea9330 100644 --- a/remote_services/topology_manager/private/src/topology_manager.c +++ b/remote_services/topology_manager/private/src/topology_manager.c @@ -313,6 +313,9 @@ celix_status_t topologyManager_rsaRemoved(void * handle, service_reference_pt re } hashMap_remove(exports, rsa); + /*if(exports_list!=NULL){ + arrayList_destroy(exports_list); + }*/ if (hashMap_size(exports) == 0) { hashMap_remove(manager->exportedServices, key); @@ -668,6 +671,7 @@ celix_status_t topologyManager_removeExportedService(topology_manager_pt manager } hashMap_remove(exports, rsa); + arrayList_destroy(exportRegistrations); hashMapIterator_destroy(iter); iter = hashMapIterator_create(exports);