Skip to content

Commit

Permalink
Add autocleanup for celix_version_range.
Browse files Browse the repository at this point in the history
  • Loading branch information
PengZheng committed Aug 6, 2023
1 parent 6dc6748 commit 7311ec5
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
14 changes: 5 additions & 9 deletions libs/framework/src/service_registry.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
#include "service_registration_private.h"
#include "listener_hook_service.h"
#include "celix_constants.h"
#include "celix_stdlib_cleanup.h"
#include "celix_version_range.h"
#include "service_reference_private.h"
#include "framework_private.h"

Expand Down Expand Up @@ -820,17 +822,15 @@ char* celix_serviceRegistry_createFilterFor(celix_service_registry_t* registry,
serviceName = "*";
}

char* versionRange = NULL;
celix_autofree char* versionRange = NULL;
if (versionRangeStr != NULL) {
version_range_pt range;
celix_status_t status = versionRange_parse(versionRangeStr, &range);
if(status != CELIX_SUCCESS) {
celix_autoptr(celix_version_range_t) range = celix_versionRange_parse(versionRangeStr);
if(range == NULL) {
celix_framework_log(registry->framework->logger, CELIX_LOG_LEVEL_ERROR, __FUNCTION__, __BASE_FILE__, __LINE__,
"Error incorrect version range.");
return NULL;
}
versionRange = versionRange_createLDAPFilter(range, CELIX_FRAMEWORK_SERVICE_VERSION);
versionRange_destroy(range);
if (versionRange == NULL) {
celix_framework_log(registry->framework->logger, CELIX_LOG_LEVEL_ERROR, __FUNCTION__, __BASE_FILE__, __LINE__,
"Error creating LDAP filter.");
Expand All @@ -849,10 +849,6 @@ char* celix_serviceRegistry_createFilterFor(celix_service_registry_t* registry,
asprintf(&filter, "(&(%s=%s))", OSGI_FRAMEWORK_OBJECTCLASS, serviceName);
}

if (versionRange != NULL){
free(versionRange);
}

return filter;
}

Expand Down
4 changes: 4 additions & 0 deletions libs/utils/gtest/src/VersionRangeTestSuite.cc
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ TEST_F(VersionRangeTestSuite, create) {
versionRange_destroy(range);
}

TEST_F(VersionRangeTestSuite, cleanup) {
celix_autoptr(celix_version_range_t) range = celix_versionRange_createInfiniteVersionRange();
}

TEST_F(VersionRangeTestSuite, createInfinite) {
celix_status_t status = CELIX_SUCCESS;
version_range_pt range = nullptr;
Expand Down
3 changes: 3 additions & 0 deletions libs/utils/include/celix_version_range.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

#include <stdbool.h>

#include "celix_cleanup.h"
#include "celix_errno.h"
#include "celix_version.h"
#include "celix_utils_export.h"
Expand Down Expand Up @@ -59,6 +60,8 @@ CELIX_UTILS_EXPORT celix_version_range_t* celix_versionRange_createInfiniteVersi

CELIX_UTILS_EXPORT void celix_versionRange_destroy(celix_version_range_t* range);

CELIX_DEFINE_AUTOPTR_CLEANUP_FUNC(celix_version_range_t, celix_versionRange_destroy)

/**
* Determine if the specified version is part of the version range or not.
*
Expand Down

0 comments on commit 7311ec5

Please sign in to comment.