CELIX-237: Some mem leak fixed based on valgrind results

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

Branch: refs/heads/feature/CELIX-237_rsa-ffi
Commit: 195c83d0747c7e13cd0ed4321f27fd2768fc3ee2
Parents: 794f797
Author: Pepijn Noltes <pepijnnol...@gmail.com>
Authored: Thu Jul 30 13:49:20 2015 +0200
Committer: Pepijn Noltes <pepijnnol...@gmail.com>
Committed: Thu Jul 30 13:49:20 2015 +0200

----------------------------------------------------------------------
 remote_services/CMakeLists.txt                  | 12 +++++-----
 .../dynamic_function_interface/dyn_common.c     | 22 +++++++++++++++--
 .../dynamic_function_interface/dyn_common.h     | 11 ++++-----
 .../dynamic_function_interface/dyn_interface.c  | 25 +++++++-------------
 .../dynamic_function_interface/dyn_interface.h  | 10 ++------
 .../tst/dyn_interface_tests.cpp                 |  5 ++++
 6 files changed, 47 insertions(+), 38 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/celix/blob/195c83d0/remote_services/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/remote_services/CMakeLists.txt b/remote_services/CMakeLists.txt
index b7dc13c..957f468 100644
--- a/remote_services/CMakeLists.txt
+++ b/remote_services/CMakeLists.txt
@@ -33,14 +33,14 @@ if (REMOTE_SERVICE_ADMIN)
 
     add_subdirectory(topology_manager)
 
-    #add_subdirectory(remote_service_admin)
-    #add_subdirectory(remote_service_admin_http)
-    add_subdirectory(remote_service_admin_http_ffi)
-    #add_subdirectory(remote_service_admin_shm)   
+    add_subdirectory(remote_service_admin)
+    add_subdirectory(remote_service_admin_http)
+    #add_subdirectory(remote_service_admin_http_ffi)
+    add_subdirectory(remote_service_admin_shm)
 
-    #add_subdirectory(discovery_configured)
+    add_subdirectory(discovery_configured)
     add_subdirectory(discovery_etcd)
-    #add_subdirectory(discovery_shm)
+    add_subdirectory(discovery_shm)
 
     add_subdirectory(dynamic_function_interface)
     

http://git-wip-us.apache.org/repos/asf/celix/blob/195c83d0/remote_services/dynamic_function_interface/dyn_common.c
----------------------------------------------------------------------
diff --git a/remote_services/dynamic_function_interface/dyn_common.c 
b/remote_services/dynamic_function_interface/dyn_common.c
index 057ddcf..0cca69b 100644
--- a/remote_services/dynamic_function_interface/dyn_common.c
+++ b/remote_services/dynamic_function_interface/dyn_common.c
@@ -51,14 +51,15 @@ int dynCommon_parseNameAlsoAccept(FILE *stream, const char 
*acceptedChars, char
         if (strLen == 0) {
             status = ERROR;
             LOG_ERROR("Parsed empty name");
-            free(buf);
         }
     }
 
     if (status == OK) {
        LOG_DEBUG("Parsed name '%s'", buf);
        *result = buf;
-    } 
+    } else if (buf != NULL) {
+        free(buf);
+    }
 
     return status;
 }
@@ -116,3 +117,20 @@ static bool dynCommon_charIn(int c, const char 
*acceptedChars) {
 
     return status;
 }
+
+void dynCommon_clearNamValHead(struct namvals_head *head) {
+    struct namval_entry *tmp = NULL;
+    struct namval_entry *entry = TAILQ_FIRST(head);
+    while (entry != NULL) {
+        tmp = entry;
+
+        if (entry->name != NULL) {
+            free(entry->name);
+        }
+        if (entry->value != NULL) {
+            free(entry->value);
+        }
+        entry = TAILQ_NEXT(entry, entries);
+        free(tmp);
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/celix/blob/195c83d0/remote_services/dynamic_function_interface/dyn_common.h
----------------------------------------------------------------------
diff --git a/remote_services/dynamic_function_interface/dyn_common.h 
b/remote_services/dynamic_function_interface/dyn_common.h
index 308b75a..a31cbc4 100644
--- a/remote_services/dynamic_function_interface/dyn_common.h
+++ b/remote_services/dynamic_function_interface/dyn_common.h
@@ -14,20 +14,19 @@
 //logging
 DFI_SETUP_LOG_HEADER(dynCommon);
 
-/*
-typedef struct _dyn_annotation_list_type annotation_list_type;
-TAILQ_HEAD(_dyn_annotation_list_type, _dyn_annotation_type);
+TAILQ_HEAD(namvals_head, namval_entry);
 
-typedef struct _dyn_annotation_type dyn_annotation_type;
-struct _dyn_annotation_type {
+struct namval_entry {
     char *name;
     char *value;
+    TAILQ_ENTRY(namval_entry) entries;
 };
-*/
 
 int dynCommon_parseName(FILE *stream, char **result);
 int dynCommon_parseNameAlsoAccept(FILE *stream, const char *acceptedChars, 
char **result);
 int dynCommon_parseNameValue(FILE *stream, char **name, char **value);
 int dynCommon_eatChar(FILE *stream, int c);
 
+void dynCommon_clearNamValHead(struct namvals_head *head);
+
 #endif 

http://git-wip-us.apache.org/repos/asf/celix/blob/195c83d0/remote_services/dynamic_function_interface/dyn_interface.c
----------------------------------------------------------------------
diff --git a/remote_services/dynamic_function_interface/dyn_interface.c 
b/remote_services/dynamic_function_interface/dyn_interface.c
index d411232..878cfea 100644
--- a/remote_services/dynamic_function_interface/dyn_interface.c
+++ b/remote_services/dynamic_function_interface/dyn_interface.c
@@ -110,18 +110,22 @@ static int dynInterface_parseSection(dyn_interface_type 
*intf, FILE *stream) {
     if (status == OK) {
         if (strcmp("header", sectionName) == 0) {
             status = dynInterface_parseHeader(intf, stream);
-        } else if (strcmp("annotations", sectionName) ==0) {
+        } else if (strcmp("annotations", sectionName) == 0) {
             status = dynInterface_parseAnnotations(intf, stream);
         } else if (strcmp("types", sectionName) == 0) {
-            status =dynInterface_parseTypes(intf, stream);
+            status = dynInterface_parseTypes(intf, stream);
         } else if (strcmp("methods", sectionName) == 0) {
-            status =dynInterface_parseMethods(intf, stream);
+            status = dynInterface_parseMethods(intf, stream);
         } else {
             status = ERROR;
             LOG_ERROR("unsupported section '%s'", sectionName);
         }
     }
 
+    if (sectionName != NULL) {
+        free(sectionName);
+    }
+
     return status;
 }
 
@@ -297,19 +301,8 @@ static int dynInterface_parseMethods(dyn_interface_type 
*intf, FILE *stream) {
 
 void dynInterface_destroy(dyn_interface_type *intf) {
     if (intf != NULL) {
-        struct namval_entry *nTmp = NULL;
-        struct namval_entry *nEntry = TAILQ_FIRST(&intf->annotations);
-        while (nEntry != NULL) {
-            nTmp = nEntry;
-            nEntry = TAILQ_NEXT(nEntry, entries);
-            if (nTmp->name != NULL) {
-                free(nTmp->name);
-            }
-            if (nTmp->value != NULL) {
-                free(nTmp->value);
-            }
-            free(nTmp);
-        }
+        dynCommon_clearNamValHead(&intf->header);
+        dynCommon_clearNamValHead(&intf->annotations);
 
         struct type_entry *tmp = NULL;
         struct type_entry *tInfo = TAILQ_FIRST(&intf->types);

http://git-wip-us.apache.org/repos/asf/celix/blob/195c83d0/remote_services/dynamic_function_interface/dyn_interface.h
----------------------------------------------------------------------
diff --git a/remote_services/dynamic_function_interface/dyn_interface.h 
b/remote_services/dynamic_function_interface/dyn_interface.h
index 6b7f9ce..41f239f 100644
--- a/remote_services/dynamic_function_interface/dyn_interface.h
+++ b/remote_services/dynamic_function_interface/dyn_interface.h
@@ -4,6 +4,7 @@
 #ifndef __DYN_INTERFACE_H_
 #define __DYN_INTERFACE_H_
 
+#include "dyn_common.h"
 #include "dyn_type.h"
 #include "dyn_function.h"
 #include "dfi_log_util.h"
@@ -22,7 +23,7 @@ DFI_SETUP_LOG_HEADER(dynInterface);
  *
  */
 
-TAILQ_HEAD(namvals_head, namval_entry);
+//struct namvals_head in dyn_common.h
 TAILQ_HEAD(methods_head, method_entry);
 //struct reference_types_head in dyn_type.h
 
@@ -35,13 +36,6 @@ struct _dyn_interface_type {
     struct methods_head methods;
 };
 
-//TODO move to dynCommon
-struct namval_entry {
-    char *name;
-    char *value;
-    TAILQ_ENTRY(namval_entry) entries;
-};
-
 struct method_entry {
     int index;
     char *id;

http://git-wip-us.apache.org/repos/asf/celix/blob/195c83d0/remote_services/dynamic_function_interface/tst/dyn_interface_tests.cpp
----------------------------------------------------------------------
diff --git 
a/remote_services/dynamic_function_interface/tst/dyn_interface_tests.cpp 
b/remote_services/dynamic_function_interface/tst/dyn_interface_tests.cpp
index 18bdb33..f60cc50 100644
--- a/remote_services/dynamic_function_interface/tst/dyn_interface_tests.cpp
+++ b/remote_services/dynamic_function_interface/tst/dyn_interface_tests.cpp
@@ -51,6 +51,11 @@ extern "C" {
         status = dynInterface_getAnnotationEntry(dynIntf, "classname", 
&annVal);
         CHECK_EQUAL(0, status);
         STRCMP_EQUAL("org.example.Calculator", annVal);
+
+        char *nonExist = NULL;
+        status = dynInterface_getHeaderEntry(dynIntf, "nonExisting", 
&nonExist);
+        CHECK(status != 0);
+        CHECK(nonExist == NULL);
         
         dynInterface_destroy(dynIntf);
     }

Reply via email to