celix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pnol...@apache.org
Subject [08/50] [abbrv] celix git commit: CELIX-374: Adapted defines and Cmake macros for RTLD_NODELETE debug-only builds. Fixed also couple of leaks found during testing.
Date Tue, 18 Oct 2016 19:26:10 GMT
CELIX-374: Adapted defines and Cmake macros for RTLD_NODELETE debug-only builds. Fixed also
couple of leaks found during testing.


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

Branch: refs/heads/release/celix-2.0.0
Commit: b92649ab54f158e98a57611949170bad95535d6c
Parents: dacd179
Author: gricciardi <gricciardi@apache.org>
Authored: Wed Sep 7 17:06:50 2016 +0200
Committer: gricciardi <gricciardi@apache.org>
Committed: Wed Sep 7 17:06:50 2016 +0200

----------------------------------------------------------------------
 CMakeLists.txt                           |  2 ++
 examples/mongoose/private/src/mongoose.c |  2 +-
 framework/private/src/framework.c        | 17 ++++++++++++++---
 framework/private/src/service_registry.c |  6 +++---
 shell/private/src/inspect_command.c      | 10 ++++++++++
 5 files changed, 30 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/celix/blob/b92649ab/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 3088612..d1c5886 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -38,6 +38,8 @@ ENDIF()
 IF(UNIX AND NOT ANDROID)
     SET(CMAKE_C_FLAGS "-D_GNU_SOURCE -std=gnu99 -Wall -Werror -fPIC ${CMAKE_C_FLAGS}")
     SET(CMAKE_CXX_FLAGS "-std=c++11 ${CMAKE_CXX_FLAGS}") #TODO enable -Wall -Werror ->
warning in cpputest
+    SET(CMAKE_C_FLAGS_DEBUG "-g -DDEBUG")
+    SET(CMAKE_CXX_FLAGS_DEBUG "-g -DDEBUG")
 ENDIF()
 IF(UNIX AND NOT APPLE) 
 	SET(CMAKE_C_FLAGS "-pthread ${CMAKE_C_FLAGS}")

http://git-wip-us.apache.org/repos/asf/celix/blob/b92649ab/examples/mongoose/private/src/mongoose.c
----------------------------------------------------------------------
diff --git a/examples/mongoose/private/src/mongoose.c b/examples/mongoose/private/src/mongoose.c
index 68f1a77..4397b94 100644
--- a/examples/mongoose/private/src/mongoose.c
+++ b/examples/mongoose/private/src/mongoose.c
@@ -1314,7 +1314,7 @@ int mg_read(struct mg_connection *conn, void *buf, size_t len) {
   const char *buffered;
 
   assert(conn->content_len >= conn->consumed_content);
-  DEBUG_TRACE(("%p %zu %lld %lld", buf, len,
+  DEBUG_TRACE(("%p %zu %ld %ld", buf, len,
                conn->content_len, conn->consumed_content));
   nread = 0;
   if (strcmp(conn->request_info.request_method, "POST") == 0 &&

http://git-wip-us.apache.org/repos/asf/celix/blob/b92649ab/framework/private/src/framework.c
----------------------------------------------------------------------
diff --git a/framework/private/src/framework.c b/framework/private/src/framework.c
index e6c736a..c6da0d5 100644
--- a/framework/private/src/framework.c
+++ b/framework/private/src/framework.c
@@ -160,6 +160,17 @@ static void framework_loggerInit(void) {
     logger->logFunction = frameworkLogger_log;
 }
 
+/* Note: RTLD_NODELETE flag is needed in order to obtain a readable valgrind output.
+ * Valgrind output is written when the application terminates, so symbols resolving
+ * is impossible if dlopened libraries are unloaded before the application ends.
+ * RTLD_NODELETE closes the dynamic library but does not unload it from the memory space,
+ * so that symbols will be available until the application terminates.
+ * On the other hand, since the memory mapping is not destroyed after dlclose, calling again
+ * dlopen for the same library clashes with the previous mapping: this breaks the memory
layout
+ * in case the user, for example, uninstall (dlclose) and install the bundle again (dlopen)
+ * So, RTLD_NODELETE should be used only for debugging purposes.
+ * Refer to dlopen manpage for additional details about libraries dynamic loading.
+ */
 #ifdef _WIN32
     #define handle_t HMODULE
     #define fw_openLibrary(path) LoadLibrary(path)
@@ -176,10 +187,10 @@ static void framework_loggerInit(void) {
     }
 #else
     #define handle_t void *
-    #ifdef ANDROID
-    #define fw_openLibrary(path) dlopen(path, RTLD_LAZY|RTLD_LOCAL)
+    #if defined(DEBUG) && !defined(ANDROID)
+	#define fw_openLibrary(path) dlopen(path, RTLD_LAZY|RTLD_LOCAL|RTLD_NODELETE)
     #else
-    #define fw_openLibrary(path) dlopen(path, RTLD_LAZY|RTLD_LOCAL|RTLD_NODELETE)
+	#define fw_openLibrary(path) dlopen(path, RTLD_LAZY|RTLD_LOCAL)
     #endif
     #define fw_closeLibrary(handle) dlclose(handle)
     #define fw_getSymbol(handle, name) dlsym(handle, name)

http://git-wip-us.apache.org/repos/asf/celix/blob/b92649ab/framework/private/src/service_registry.c
----------------------------------------------------------------------
diff --git a/framework/private/src/service_registry.c b/framework/private/src/service_registry.c
index a5dd20c..49f0638 100644
--- a/framework/private/src/service_registry.c
+++ b/framework/private/src/service_registry.c
@@ -35,10 +35,10 @@
 #include "service_reference_private.h"
 #include "framework_private.h"
 
-#ifdef NDEBUG
-#define CHECK_DELETED_REFERENCES false
-#else
+#ifdef DEBUG
 #define CHECK_DELETED_REFERENCES true
+#else
+#define CHECK_DELETED_REFERENCES false
 #endif
 
 static celix_status_t serviceRegistry_registerServiceInternal(service_registry_pt registry,
bundle_pt bundle, const char* serviceName, const void * serviceObject, properties_pt dictionary,
bool isFactory, service_registration_pt *registration);

http://git-wip-us.apache.org/repos/asf/celix/blob/b92649ab/shell/private/src/inspect_command.c
----------------------------------------------------------------------
diff --git a/shell/private/src/inspect_command.c b/shell/private/src/inspect_command.c
index f53a163..cb93e9c 100644
--- a/shell/private/src/inspect_command.c
+++ b/shell/private/src/inspect_command.c
@@ -149,6 +149,8 @@ celix_status_t inspectCommand_printExportedServices(bundle_context_pt
context, a
 										fprintf(outStream, "%s = %s\n", key, value);
 									}
 
+									free(keys);
+
 //									objectClass = properties_get(props, (char *) OSGI_FRAMEWORK_OBJECTCLASS);
 //									sprintf(line, "ObjectClass = %s\n", objectClass);
 									if ((j + 1) < arrayList_size(refs)) {
@@ -159,6 +161,10 @@ celix_status_t inspectCommand_printExportedServices(bundle_context_pt
context, a
 						}
 					}
 				}
+
+				if(refs!=NULL){
+					arrayList_destroy(refs);
+				}
 			}
 		}
 	}
@@ -256,6 +262,10 @@ celix_status_t inspectCommand_printImportedServices(bundle_context_pt
context, a
                         }
                     }
                 }
+
+                if(refs!=NULL){
+                	arrayList_destroy(refs);
+                }
             }
         }
     }


Mime
View raw message