Repository: celix
Updated Branches:
  refs/heads/develop 3dac5aae0 -> f4482bce2


Fixes a mem issue and cpputest issue


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

Branch: refs/heads/develop
Commit: f4482bce23011d56b880d28fc28015b5117eb42f
Parents: 3dac5aa
Author: Pepijn Noltes <[email protected]>
Authored: Wed Mar 21 14:37:12 2018 +0100
Committer: Pepijn Noltes <[email protected]>
Committed: Wed Mar 21 14:37:12 2018 +0100

----------------------------------------------------------------------
 .../private/test/service_reference_test.cpp     | 50 ++++++++++----------
 pubsub/pubsub_spi/include/pubsub_utils.h        |  2 +-
 pubsub/pubsub_spi/src/pubsub_endpoint.c         | 11 +++--
 pubsub/pubsub_spi/src/pubsub_utils.c            | 10 ++--
 4 files changed, 40 insertions(+), 33 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/celix/blob/f4482bce/framework/private/test/service_reference_test.cpp
----------------------------------------------------------------------
diff --git a/framework/private/test/service_reference_test.cpp 
b/framework/private/test/service_reference_test.cpp
index 4d5f3c6..8d2bad4 100644
--- a/framework/private/test/service_reference_test.cpp
+++ b/framework/private/test/service_reference_test.cpp
@@ -333,7 +333,7 @@ TEST(service_reference, getProperty){
                        .withParameter("registration", registration)
                        .withOutputParameterReturning("properties", &props, 
sizeof(props));
 
-       mock().expectOneCall("properties_getWithDefault")
+       mock().expectOneCall("properties_get")
                        .withParameter("key", key)
                        .withParameter("properties", props)
                        .ignoreOtherParameters()
@@ -559,23 +559,23 @@ TEST(service_reference, compareTo){
                        .withOutputParameterReturning("properties", &props2, 
sizeof(props2));
 
        //service 1 is higher ranked and has a irrelevant ID
-       mock().expectOneCall("properties_getWithDefault")
+       mock().expectOneCall("properties_get")
                        .withParameter("key", OSGI_FRAMEWORK_SERVICE_ID)
                        .withParameter("properties", props)
                        .ignoreOtherParameters()
                        .andReturnValue("2");
-       mock().expectOneCall("properties_getWithDefault")
+       mock().expectOneCall("properties_get")
                        .withParameter("key", OSGI_FRAMEWORK_SERVICE_ID)
                        .withParameter("properties", props2)
                        .ignoreOtherParameters()
                        .andReturnValue("1");
 
-       mock().expectOneCall("properties_getWithDefault")
+       mock().expectOneCall("properties_get")
                        .withParameter("key", OSGI_FRAMEWORK_SERVICE_RANKING)
                        .withParameter("properties", props)
                        .ignoreOtherParameters()
                        .andReturnValue("2");
-       mock().expectOneCall("properties_getWithDefault")
+       mock().expectOneCall("properties_get")
                        .withParameter("key", OSGI_FRAMEWORK_SERVICE_RANKING)
                        .withParameter("properties", props2)
                        .ignoreOtherParameters()
@@ -585,23 +585,23 @@ TEST(service_reference, compareTo){
        LONGS_EQUAL(1, compare);
 
        //service 1 is equally ranked and has a lower ID
-       mock().expectOneCall("properties_getWithDefault")
+       mock().expectOneCall("properties_get")
                        .withParameter("key", OSGI_FRAMEWORK_SERVICE_ID)
                        .withParameter("properties", props)
                        .ignoreOtherParameters()
                        .andReturnValue("1");
-       mock().expectOneCall("properties_getWithDefault")
+       mock().expectOneCall("properties_get")
                        .withParameter("key", OSGI_FRAMEWORK_SERVICE_ID)
                        .withParameter("properties", props2)
                        .ignoreOtherParameters()
                        .andReturnValue("2");
 
-       mock().expectOneCall("properties_getWithDefault")
+       mock().expectOneCall("properties_get")
                        .withParameter("key", OSGI_FRAMEWORK_SERVICE_RANKING)
                        .withParameter("properties", props)
                        .ignoreOtherParameters()
                        .andReturnValue("1");
-       mock().expectOneCall("properties_getWithDefault")
+       mock().expectOneCall("properties_get")
                        .withParameter("key", OSGI_FRAMEWORK_SERVICE_RANKING)
                        .ignoreOtherParameters()
                        .withParameter("properties", props2)
@@ -611,23 +611,23 @@ TEST(service_reference, compareTo){
        LONGS_EQUAL(1, compare);
 
        //service 1 is equally ranked and has a higher ID
-       mock().expectOneCall("properties_getWithDefault")
+       mock().expectOneCall("properties_get")
                        .withParameter("key", OSGI_FRAMEWORK_SERVICE_ID)
                        .ignoreOtherParameters()
                        .withParameter("properties", props)
                        .andReturnValue("2");
-       mock().expectOneCall("properties_getWithDefault")
+       mock().expectOneCall("properties_get")
                        .withParameter("key", OSGI_FRAMEWORK_SERVICE_ID)
                        .withParameter("properties", props2)
                        .ignoreOtherParameters()
                        .andReturnValue("1");
 
-       mock().expectOneCall("properties_getWithDefault")
+       mock().expectOneCall("properties_get")
                        .withParameter("key", OSGI_FRAMEWORK_SERVICE_RANKING)
                        .ignoreOtherParameters()
                        .withParameter("properties", props)
                        .andReturnValue("1");
-       mock().expectOneCall("properties_getWithDefault")
+       mock().expectOneCall("properties_get")
                        .withParameter("key", OSGI_FRAMEWORK_SERVICE_RANKING)
                        .ignoreOtherParameters()
                        .withParameter("properties", props2)
@@ -637,23 +637,23 @@ TEST(service_reference, compareTo){
        LONGS_EQUAL(-1, compare);
 
        //service 1 is lower ranked and has a irrelevant ID
-       mock().expectOneCall("properties_getWithDefault")
+       mock().expectOneCall("properties_get")
                        .withParameter("key", OSGI_FRAMEWORK_SERVICE_ID)
                        .ignoreOtherParameters()
                        .withParameter("properties", props)
                        .andReturnValue("1");
-       mock().expectOneCall("properties_getWithDefault")
+       mock().expectOneCall("properties_get")
                        .withParameter("key", OSGI_FRAMEWORK_SERVICE_ID)
                        .ignoreOtherParameters()
                        .withParameter("properties", props2)
                        .andReturnValue("2");
 
-       mock().expectOneCall("properties_getWithDefault")
+       mock().expectOneCall("properties_get")
                        .withParameter("key", OSGI_FRAMEWORK_SERVICE_RANKING)
                        .ignoreOtherParameters()
                        .withParameter("properties", props)
                        .andReturnValue("1");
-       mock().expectOneCall("properties_getWithDefault")
+       mock().expectOneCall("properties_get")
                        .withParameter("key", OSGI_FRAMEWORK_SERVICE_RANKING)
                        .ignoreOtherParameters()
                        .withParameter("properties", props2)
@@ -663,23 +663,23 @@ TEST(service_reference, compareTo){
        LONGS_EQUAL(-1, compare);
 
        //service 1 is equal in ID and irrelevantly ranked
-       mock().expectOneCall("properties_getWithDefault")
+       mock().expectOneCall("properties_get")
                        .withParameter("key", OSGI_FRAMEWORK_SERVICE_ID)
                        .ignoreOtherParameters()
                        .withParameter("properties", props)
                        .andReturnValue("1);");
-       mock().expectOneCall("properties_getWithDefault")
+       mock().expectOneCall("properties_get")
                        .withParameter("key", OSGI_FRAMEWORK_SERVICE_ID)
                        .ignoreOtherParameters()
                        .withParameter("properties", props2)
                        .andReturnValue("1");
 
-       mock().expectOneCall("properties_getWithDefault")
+       mock().expectOneCall("properties_get")
                        .withParameter("key", OSGI_FRAMEWORK_SERVICE_RANKING)
                        .ignoreOtherParameters()
                        .withParameter("properties", props)
                        .andReturnValue("1");
-       mock().expectOneCall("properties_getWithDefault")
+       mock().expectOneCall("properties_get")
                        .withParameter("key", OSGI_FRAMEWORK_SERVICE_RANKING)
                        .ignoreOtherParameters()
                        .withParameter("properties", props2)
@@ -689,23 +689,23 @@ TEST(service_reference, compareTo){
        LONGS_EQUAL(0, compare);
 
        //services have no rank and service 1 has a higher ID
-       mock().expectOneCall("properties_getWithDefault")
+       mock().expectOneCall("properties_get")
                        .withParameter("key", OSGI_FRAMEWORK_SERVICE_ID)
                        .ignoreOtherParameters()
                        .withParameter("properties", props)
                        .andReturnValue("2");
-       mock().expectOneCall("properties_getWithDefault")
+       mock().expectOneCall("properties_get")
                        .withParameter("key", OSGI_FRAMEWORK_SERVICE_ID)
                        .ignoreOtherParameters()
                        .withParameter("properties", props2)
                        .andReturnValue("1");
 
-       mock().expectOneCall("properties_getWithDefault")
+       mock().expectOneCall("properties_get")
                        .withParameter("key", OSGI_FRAMEWORK_SERVICE_RANKING)
                        .ignoreOtherParameters()
                        .withParameter("properties", props)
                        .andReturnValue((void*)NULL);
-       mock().expectOneCall("properties_getWithDefault")
+       mock().expectOneCall("properties_get")
                        .withParameter("key", OSGI_FRAMEWORK_SERVICE_RANKING)
                        .ignoreOtherParameters()
                        .withParameter("properties", props2)

http://git-wip-us.apache.org/repos/asf/celix/blob/f4482bce/pubsub/pubsub_spi/include/pubsub_utils.h
----------------------------------------------------------------------
diff --git a/pubsub/pubsub_spi/include/pubsub_utils.h 
b/pubsub/pubsub_spi/include/pubsub_utils.h
index e4c08ec..96d20a4 100644
--- a/pubsub/pubsub_spi/include/pubsub_utils.h
+++ b/pubsub/pubsub_spi/include/pubsub_utils.h
@@ -30,7 +30,7 @@
 #include "bundle_context.h"
 #include "array_list.h"
 
-celix_status_t pubsub_getPubSubInfoFromFilter(const char* filterstr, const 
char **topic, const char **scope);
+celix_status_t pubsub_getPubSubInfoFromFilter(const char* filterstr, char 
**topic, char **scope);
 char* pubsub_getKeysBundleDir(bundle_context_pt ctx);
 
 

http://git-wip-us.apache.org/repos/asf/celix/blob/f4482bce/pubsub/pubsub_spi/src/pubsub_endpoint.c
----------------------------------------------------------------------
diff --git a/pubsub/pubsub_spi/src/pubsub_endpoint.c 
b/pubsub/pubsub_spi/src/pubsub_endpoint.c
index 2f480a8..535ade0 100644
--- a/pubsub/pubsub_spi/src/pubsub_endpoint.c
+++ b/pubsub/pubsub_spi/src/pubsub_endpoint.c
@@ -259,18 +259,19 @@ celix_status_t 
pubsubEndpoint_createFromListenerHookInfo(bundle_context_t *ctx,
                return CELIX_BUNDLE_EXCEPTION;
        }
 
-       const char* topic = NULL;
-       const char* scope = NULL;
+       char* topic = NULL;
+       char* scope = NULL;
        pubsub_getPubSubInfoFromFilter(info->filter, &topic, &scope);
 
        if (topic==NULL) {
+               free(scope);
                return CELIX_BUNDLE_EXCEPTION;
        }
-       if(scope == NULL) {
+       if (scope == NULL) {
                scope = strdup(PUBSUB_PUBLISHER_SCOPE_DEFAULT);
        }
 
-    pubsub_endpoint_pt psEp = calloc(1, sizeof(**out));
+        pubsub_endpoint_pt psEp = calloc(1, sizeof(**out));
 
        bundle_pt bundle = NULL;
        long bundleId = -1;
@@ -281,6 +282,8 @@ celix_status_t 
pubsubEndpoint_createFromListenerHookInfo(bundle_context_t *ctx,
 
        /* TODO: is topic_props==NULL a fatal error such that EP cannot be 
created? */
        pubsubEndpoint_setFields(psEp, fwUUID, scope, topic, bundleId, -1, 
NULL, PUBSUB_PUBLISHER_ENDPOINT_TYPE, topic_props);
+       free(scope);
+       free(topic);
 
     if (!pubsubEndpoint_isEndpointValid(psEp)) {
         status = CELIX_ILLEGAL_STATE;

http://git-wip-us.apache.org/repos/asf/celix/blob/f4482bce/pubsub/pubsub_spi/src/pubsub_utils.c
----------------------------------------------------------------------
diff --git a/pubsub/pubsub_spi/src/pubsub_utils.c 
b/pubsub/pubsub_spi/src/pubsub_utils.c
index 5978ec7..f60d677 100644
--- a/pubsub/pubsub_spi/src/pubsub_utils.c
+++ b/pubsub/pubsub_spi/src/pubsub_utils.c
@@ -43,7 +43,7 @@
 #define MAX_KEYBUNDLE_LENGTH 256
 
 
-celix_status_t pubsub_getPubSubInfoFromFilter(const char* filterstr, const 
char **topicOut, const char **scopeOut) {
+celix_status_t pubsub_getPubSubInfoFromFilter(const char* filterstr, char 
**topicOut, char **scopeOut) {
        celix_status_t status = CELIX_SUCCESS;
        const char *topic = NULL;
        const char *scope = NULL;
@@ -71,12 +71,16 @@ celix_status_t pubsub_getPubSubInfoFromFilter(const char* 
filterstr, const char
        filter_destroy(filter);
 
        if (topic != NULL && objectClass != NULL && strncmp(objectClass, 
PUBSUB_PUBLISHER_SERVICE_NAME, 128) == 0) {
-               *topicOut = topic;
-               *scopeOut = scope;
+               *topicOut = strdup(topic);
+               *scopeOut = strdup(scope);
        } else {
                *topicOut = NULL;
                *scopeOut = NULL;
        }
+
+       if (filter != NULL) {
+             filter_destroy(filter);
+        }
        return status;
 }
 

Reply via email to