Fixed memory leaks in ZeroMQ integration code; additional check for correct libzmq...
authorVictor Kirhenshtein <victor@netxms.org>
Fri, 25 Dec 2015 12:28:02 +0000 (14:28 +0200)
committerVictor Kirhenshtein <victor@netxms.org>
Fri, 25 Dec 2015 12:28:02 +0000 (14:28 +0200)
ChangeLog
configure.ac
include/nms_util.h
src/server/core/Makefile.am
src/server/core/zeromq.cpp

index cf83aaf..2c9e3f7 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -24,7 +24,7 @@
        - Line width can be configured for line charts on dashboards
        - Column sizes saved in table DCI last values view
        - Rack height and numbering direction can be changed
-- Fixed issues: #205, #847, #849, #948, #963, #967, #971, #974, #978, #979, #980, #983, #991, #997, #1002, #1003, #1004, #1013, #1019, #1024, #1029, #1032, #1058, #1071, #1072, #1074, #1081, #1082, #1083, #1084, #1085
+- Fixed issues: #205, #847, #849, #948, #963, #966, #967, #971, #974, #978, #979, #980, #983, #991, #997, #1002, #1003, #1004, #1013, #1019, #1024, #1029, #1032, #1058, #1071, #1072, #1074, #1081, #1082, #1083, #1084, #1085
 
 
 *
index cceb2f2..dcf227e 100644 (file)
@@ -92,11 +92,12 @@ RUNTIME_PREFIX=""
 RUNTIME_STATE_DIR=""
 HPUX_HPPA="no"
 XMPP_SUPPORT="yes"
-ZMQ_SUPPORT="no"
+ZEROMQ_SUPPORT="no"
+ZEROMQ_CPPFLAGS=""
+ZEROMQ_LDFLAGS=""
 LDAP_SUPPORT="yes"
 DISABLE_READLINE="no"
 TUXEDO_LIBS=""
-ZEROMQ_LIBS=""
 MONGODB_LIBS=""
 DISABLE_IPV6="no"
 IPV6_SUPPORT="no"
@@ -280,7 +281,7 @@ AC_ARG_WITH(zeromq,
                ZEROMQ_BASE="$withval"
        fi
        COMPONENTS="$COMPONENTS zeromq"
-   ZMQ_SUPPORT=yes
+   ZEROMQ_SUPPORT=yes
 fi ])
 
 AC_ARG_WITH(mongodb,
@@ -2829,15 +2830,10 @@ if test $? = 0; then
                ZEROMQ_LDFLAGS="-L$ZEROMQ_BASE/lib"
                CPPFLAGS="$CPPFLAGS $ZEROMQ_CPPFLAGS"
                LDFLAGS="$LDFLAGS $ZEROMQ_LDFLAGS"
-       else
-        ZEROMQ_CPPFLAGS="-I/usr/local/include"
-               ZEROMQ_LDFLAGS="-L/usr/local/lib"
-               CPPFLAGS="$CPPFLAGS $ZEROMQ_CPPFLAGS"
-               LDFLAGS="$LDFLAGS $ZEROMQ_LDFLAGS"
-    fi
+       fi
        
        AC_CHECK_HEADER(zmq.h,,AC_MSG_ERROR([*** Cannot find zmq.h - check your ZeroMQ installation ***]))
-       AC_CHECK_LIB(zmq, zmq_sleep, [ SERVER_LIBS="$SERVER_LIBS -lzmq" ])
+       AC_CHECK_LIB(zmq, zmq_ctx_new, [ SERVER_LIBS="$SERVER_LIBS -lzmq" ], AC_MSG_ERROR([*** libzmq is missing or too old - check your ZeroMQ installation ***]))
     
        AC_DEFINE(WITH_ZMQ, 1, Define to 1 if ZeroMQ is supported)
 
@@ -2932,7 +2928,7 @@ AM_CONDITIONAL([ALL_STATIC], [test "x$ALL_STATIC" = "xyes"])
 AM_CONDITIONAL([USE_ENCRYPTION], [test "x${ac_cv_lib_crypto_RSA_new}" = "xyes"])
 AM_CONDITIONAL([HPUX_HPPA], [test "x$HPUX_HPPA" = "xyes"])
 AM_CONDITIONAL([XMPP_SUPPORT], [test "x$XMPP_SUPPORT" = "xyes"])
-AM_CONDITIONAL([ZMQ_SUPPORT], [test "x$ZMQ_SUPPORT" = "xyes"])
+AM_CONDITIONAL([ZEROMQ_SUPPORT], [test "x$ZEROMQ_SUPPORT" = "xyes"])
 
 
 #--------------------------------------------------------------------
@@ -2991,13 +2987,12 @@ AC_SUBST(SHLIB_SUFFIX)
 AC_SUBST(TUXEDO_CPPFLAGS)
 AC_SUBST(TUXEDO_LDFLAGS)
 AC_SUBST(TUXEDO_LIBS)
-AC_SUBST(ZEROMQ_CPPFLAGS)
-AC_SUBST(ZEROMQ_LDFLAGS)
-AC_SUBST(ZEROMQ_LIBS)
 AC_SUBST(MONGODB_CPPFLAGS)
 AC_SUBST(MONGODB_LDFLAGS)
 AC_SUBST(MONGODB_LIBS)
 AC_SUBST(INSTALL_LIBPATH)
+AC_SUBST(ZEROMQ_CPPFLAGS)
+AC_SUBST(ZEROMQ_LDFLAGS)
 
 #--------------------------------------------------------------------
 # Shared libs versions
@@ -3280,7 +3275,7 @@ if test "x${BUILD_SERVER}" = "xyes"; then
        else
                echo "XMPP support            : NO"
        fi
-       if test "x${ZMQ_SUPPORT}" = "xyes"; then
+       if test "x${ZEROMQ_SUPPORT}" = "xyes"; then
                echo "ZeroMQ support          : YES"
        else
                echo "ZeroMQ support          : NO"
index ad33afa..ee4b903 100644 (file)
@@ -221,9 +221,9 @@ char LIBNETXMS_EXPORTABLE *UTF8StringFromWideString(const WCHAR *pwszString);
 #endif
 
 #ifdef UNICODE
-#define UTF8StringFromTchar(x) UTF8StringFromWideString(x)
+#define UTF8StringFromTString(s) UTF8StringFromWideString(s)
 #else
-#define UTF8StringFromTchar(x) x
+#define UTF8StringFromTString(s) UTF8StringFromMBString(s)
 #endif
 
 /**
index 210d270..4a24301 100644 (file)
@@ -32,8 +32,8 @@ libnxcore_la_SOURCES =  accesspoint.cpp acl.cpp actions.cpp admin.cpp \
                        uniroot.cpp upload_job.cpp uptimecalc.cpp userdb.cpp \
                        userdb_objects.cpp vpnconn.cpp vrrp.cpp watchdog.cpp \
                        winperf.cpp xmpp.cpp zeromq.cpp zone.cpp
-libnxcore_la_CPPFLAGS=-I@top_srcdir@/include -I@top_srcdir@/src/server/include
-libnxcore_la_LDFLAGS = -version-info $(NETXMS_LIBRARY_VERSION) 
+libnxcore_la_CPPFLAGS=-I@top_srcdir@/include -I@top_srcdir@/src/server/include @ZEROMQ_CPPFLAGS@
+libnxcore_la_LDFLAGS = -version-info $(NETXMS_LIBRARY_VERSION) @ZEROMQ_LDFLAGS@
 libnxcore_la_LIBADD = \
        ../libnxsrv/libnxsrv.la \
        ../../snmp/libnxsnmp/libnxsnmp.la \
@@ -54,7 +54,7 @@ if USE_INTERNAL_LIBTRE
 libnxcore_la_LIBADD += @top_srcdir@/src/libtre/libnxtre.la
 endif
 
-if ZMQ_SUPPORT
+if ZEROMQ_SUPPORT
 if USE_INTERNAL_JANSSON
 libnxcore_la_LIBADD += @top_srcdir@/src/jansson/libnxjansson.la
 else
index 3c43ce9..b029427 100644 (file)
@@ -102,7 +102,6 @@ bool Subscription::removeItem(UINT32 dciId)
    return !ignoreItems && items->size() == 0;
 }
 
-
 /**
  *
  */
@@ -111,11 +110,11 @@ bool Subscription::match(UINT32 dciId)
    return ignoreItems || items->contains(dciId);
 }
 
-
 /**
- *
+ * Load subscriptions from database
  */
-static void LoadSubscriptions() {
+static void LoadSubscriptions()
+{
    DB_HANDLE db = DBConnectionPoolAcquireConnection();
        DB_RESULT result = DBSelect(db, _T("SELECT object_id, subscription_type, ignore_items, items FROM zmq_subscription"));
    if (result != NULL)
@@ -235,11 +234,11 @@ static bool SaveSubscriptionInternal(DB_STATEMENT statement, HashMap<UINT32, Sub
    return true;
 }
 
-
 /**
- *
+ * Save subscriptions to database
  */
-static bool SaveSubscriptions() {
+static bool SaveSubscriptions()
+{
    DB_HANDLE db = DBConnectionPoolAcquireConnection();
 
    bool success = false;
@@ -272,14 +271,21 @@ static bool SaveSubscriptions() {
    }
 
    DBConnectionPoolReleaseConnection(db);
-
    return success;
 }
 
-
+/**
+ * Add dynamic string to JSON
+ */
+inline json_t *json_string_dynamic(char *s)
+{
+   json_t *json = json_string(s);
+   free(s);
+   return json;
+}
 
 /**
- *
+ * Convert event object to JSON representation
  */
 static char *EventToJson(const Event *event, const NetObj *object)
 {
@@ -294,12 +300,12 @@ static char *EventToJson(const Event *event, const NetObj *object)
    json_object_set_new(root, "time", json_integer(event->getTimeStamp()));
    json_object_set_new(root, "code", json_integer(event->getCode()));
    json_object_set_new(root, "severity", json_integer(event->getSeverity()));
-   json_object_set_new(root, "message", json_string(UTF8StringFromTchar(event->getMessage())));
+   json_object_set_new(root, "message", json_string_dynamic(UTF8StringFromTString(event->getMessage())));
 
    json_object_set_new(source, "id", json_integer(event->getSourceId()));
    int objectType = object->getObjectClass();
    json_object_set_new(source, "type", json_integer(objectType));
-   json_object_set_new(source, "name", json_string(UTF8StringFromTchar(object->getName())));
+   json_object_set_new(source, "name", json_string_dynamic(UTF8StringFromTString(object->getName())));
    if (objectType == OBJECT_NODE)
    {
       InetAddress ip = ((Node *)object)->getIpAddress();
@@ -312,7 +318,7 @@ static char *EventToJson(const Event *event, const NetObj *object)
    {
       char name[16];
       sprintf(name, "p%d", i+1);
-      json_object_set_new(args, name, json_string(UTF8StringFromTchar(event->getParameter(i))));
+      json_object_set_new(args, name, json_string_dynamic(UTF8StringFromTString(event->getParameter(i))));
    }
 
    char *message = json_dumps(root, 0);
@@ -320,9 +326,8 @@ static char *EventToJson(const Event *event, const NetObj *object)
    return message;
 }
 
-
 /**
- *
+ * Convert DCI value to JSON representation
  */
 static char *DataToJson(const NetObj *object, UINT32 dciId, const TCHAR *dciName, const TCHAR *value)
 {
@@ -335,7 +340,9 @@ static char *DataToJson(const NetObj *object, UINT32 dciId, const TCHAR *dciName
 
    json_t *record = json_object();
    json_object_set_new(record, "id", json_integer(dciId));
-   json_object_set_new(record, UTF8StringFromTchar(dciName), json_string(UTF8StringFromTchar(value)));
+   char *utf8name = UTF8StringFromTString(dciName);
+   json_object_set_new(record, utf8name, json_string_dynamic(UTF8StringFromTString(value)));
+   free(utf8name);
    json_array_append(data, record);
 
    char *message = json_dumps(root, 0);
@@ -343,9 +350,8 @@ static char *DataToJson(const NetObj *object, UINT32 dciId, const TCHAR *dciName
    return message;
 }
 
-
 /**
- *
+ * Subscribe
  */
 static bool Subscribe(HashMap<UINT32, Subscription> *map, MUTEX mutex, UINT32 objectId, UINT32 dciId)
 {