You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@celix.apache.org by pn...@apache.org on 2023/03/30 13:41:18 UTC

[celix] branch feature/refactor_bundle_cache updated: Fix some small race conditions, mem leaks and commented out code

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

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


The following commit(s) were added to refs/heads/feature/refactor_bundle_cache by this push:
     new 3882af52 Fix some small race conditions, mem leaks and commented out code
3882af52 is described below

commit 3882af528807b6821d6f8f903216d7fd3777d46e
Author: Pepijn Noltes <pe...@gmail.com>
AuthorDate: Thu Mar 30 15:41:03 2023 +0200

    Fix some small race conditions, mem leaks and commented out code
---
 libs/framework/src/bundle.c         |  8 ++------
 libs/framework/src/bundle_archive.c | 11 ++++++++++-
 2 files changed, 12 insertions(+), 7 deletions(-)

diff --git a/libs/framework/src/bundle.c b/libs/framework/src/bundle.c
index 295ccc53..2d7876aa 100644
--- a/libs/framework/src/bundle.c
+++ b/libs/framework/src/bundle.c
@@ -64,6 +64,7 @@ celix_status_t celix_bundle_createFromArchive(celix_framework_t *framework, bund
     if (bundle->modules == NULL) {
         status = CELIX_ENOMEM;
         fw_logCode(framework->logger, CELIX_LOG_LEVEL_ERROR, status, "Cannot create bundle from archive, out of memory.");
+        free(bundle);
         return status;
     }
 
@@ -303,11 +304,6 @@ celix_status_t bundle_revise(bundle_pt bundle, const char * location, const char
 	return status;
 }
 
-//bool bundle_rollbackRevise(bundle_pt bundle) {
-//	module_pt module = arrayList_remove(bundle->modules, arrayList_set(bundle->modules) - 1);
-//	return resolver_removeModule(module);
-//}
-
 celix_status_t bundle_addModule(bundle_pt bundle, module_pt module) {
 	celix_arrayList_add(bundle->modules, module);
 	resolver_addModule(module);
@@ -355,7 +351,7 @@ celix_status_t bundle_isSystemBundle(const_bundle_pt bundle, bool *systemBundle)
 }
 
 celix_status_t bundle_close(const_bundle_pt bundle) {
-    fw_log(bundle->framework->logger, CELIX_LOG_LEVEL_DEBUG, "Usage of bundle_close is deprecated. Called for bundle %s", bundle->symbolicName);
+    fw_log(bundle->framework->logger, CELIX_LOG_LEVEL_DEBUG, "Usage of bundle_close is deprecated and no longer needed. Called for bundle %s", bundle->symbolicName);
     return CELIX_SUCCESS;
 }
 
diff --git a/libs/framework/src/bundle_archive.c b/libs/framework/src/bundle_archive.c
index 1a8b1114..65f61d73 100644
--- a/libs/framework/src/bundle_archive.c
+++ b/libs/framework/src/bundle_archive.c
@@ -315,7 +315,9 @@ const char* celix_bundleArchive_getSymbolicName(bundle_archive_pt archive) {
 }
 
 celix_status_t bundleArchive_getLocation(bundle_archive_pt archive, const char **location) {
+    celixThreadMutex_lock(&archive->lock);
     *location = archive->location;
+    celixThreadMutex_unlock(&archive->lock);
     return CELIX_SUCCESS;
 }
 
@@ -330,7 +332,9 @@ celix_status_t bundleArchive_getCurrentRevisionNumber(bundle_archive_pt archive,
 }
 
 celix_status_t bundleArchive_getCurrentRevision(bundle_archive_pt archive, bundle_revision_pt *revision) {
+    celixThreadMutex_lock(&archive->lock);
     *revision = archive->revision;
+    celixThreadMutex_unlock(&archive->lock);
     return CELIX_SUCCESS;
 }
 
@@ -388,7 +392,12 @@ celix_status_t celix_bundleArchive_getLastModified(bundle_archive_pt archive, st
 }
 
 celix_status_t bundleArchive_setLastModified(bundle_archive_pt archive __attribute__((unused)), time_t lastModifiedTime  __attribute__((unused))) {
-    return celix_utils_touch(archive->archiveRoot);
+    celix_status_t status = CELIX_SUCCESS;
+    char manifestPathBuffer[CELIX_DEFAULT_STRING_CREATE_BUFFER_SIZE];
+    char* manifestPath = celix_utils_writeOrCreateString(manifestPathBuffer, sizeof(manifestPathBuffer), "%s/%s", archive->resourceCacheRoot, CELIX_BUNDLE_MANIFEST_REL_PATH);
+    status = celix_utils_touch(manifestPath);
+    celix_utils_freeStringIfNotEqual(manifestPathBuffer, manifestPath);
+    return status;
 }
 
 celix_status_t bundleArchive_revise(bundle_archive_pt archive, const char * location __attribute__((unused)), const char *updatedBundleUrl) {