fixed memory leak in alarms; fixed invalid memory access on server shutdown; updated...
authorVictor Kirhenshtein <victor@netxms.org>
Thu, 13 Oct 2016 16:07:43 +0000 (19:07 +0300)
committerVictor Kirhenshtein <victor@netxms.org>
Thu, 13 Oct 2016 16:07:43 +0000 (19:07 +0300)
doc/valgrind.supp
src/server/core/alarm.cpp
src/server/core/schedule.cpp

index 1566716..3d7b4d6 100644 (file)
 }
 
 {
 }
 
 {
+       OpenSSL/DH_new_method
+       Memcheck:Leak
+       fun:malloc
+       fun:CRYPTO_malloc
+       ...
+       fun:DH_new_method
+}
+
+{
+       OpenSSL/OpenSSL_add_all_ciphers
+       Memcheck:Leak
+       fun:malloc
+       fun:CRYPTO_malloc
+       ...
+       fun:OpenSSL_add_all_ciphers
+}
+
+{
+       OpenSSL/OpenSSL_add_all_digests
+       Memcheck:Leak
+       fun:malloc
+       fun:CRYPTO_malloc
+       ...
+       fun:OpenSSL_add_all_digests
+}
+
+{
+       OpenSSL/OPENSSL_load_builtin_modules
+       Memcheck:Leak
+       fun:malloc
+       fun:CRYPTO_malloc
+       ...
+       fun:OPENSSL_load_builtin_modules
+}
+
+{
+       OpenSSL/ENGINE_load_builtin_engines
+       Memcheck:Leak
+       fun:malloc
+       fun:CRYPTO_malloc
+       ...
+       fun:ENGINE_load_builtin_engines
+}
+
+{
+       OpenSSL/CONF_modules_load_file
+       Memcheck:Leak
+       fun:malloc
+       fun:CRYPTO_malloc
+       ...
+       fun:CONF_modules_load_file
+}
+
+{
+       OpenSSL/SSL_library_init
+       Memcheck:Leak
+       fun:malloc
+       fun:CRYPTO_malloc
+       ...
+       fun:SSL_library_init
+}
+
+{
        uninit bytes in agent send message
        Memcheck:Param
        socketcall.sendto
        uninit bytes in agent send message
        Memcheck:Param
        socketcall.sendto
 }
 
 {
 }
 
 {
+       Oracle Client 12/Jump
+       Memcheck:Cond
+       obj:*/libclntsh.so.12.1
+}
+
+{
        Oracle Client 12/Uninitialized 8
        Memcheck:Value8
        obj:*/libnnz12.so
        Oracle Client 12/Uninitialized 8
        Memcheck:Value8
        obj:*/libnnz12.so
        fun:calloc
        obj:*/libclntshcore.so.12.1
 }
        fun:calloc
        obj:*/libclntshcore.so.12.1
 }
+
+{
+       Static mutexes
+       Memcheck:Leak
+       fun:malloc
+       fun:MutexCreate
+       fun:__static_initialization_and_destruction_0
+}
+
+{
+       Static conditions
+       Memcheck:Leak
+       fun:malloc
+       fun:ConditionCreate
+       fun:__static_initialization_and_destruction_0
+}
index 723e8b7..118431b 100644 (file)
@@ -137,8 +137,9 @@ Alarm::Alarm(DB_HANDLE hdb, DB_RESULT hResult, int row)
    for(int i = 0; i < count; i++)
    {
       m_alarmCategoryList->add(_tcstoul(ids[i], NULL, 10));
    for(int i = 0; i < count; i++)
    {
       m_alarmCategoryList->add(_tcstoul(ids[i], NULL, 10));
-      free(ids);
+      free(ids[i]);
    }
    }
+   free(ids);
 }
 
 /**
 }
 
 /**
index acdac0a..dd7f72f 100644 (file)
@@ -28,7 +28,7 @@
 static StringObjectMap<SchedulerCallback> s_callbacks(true);
 static ObjectArray<ScheduledTask> s_cronSchedules(5, 5, true);
 static ObjectArray<ScheduledTask> s_oneTimeSchedules(5, 5, true);
 static StringObjectMap<SchedulerCallback> s_callbacks(true);
 static ObjectArray<ScheduledTask> s_cronSchedules(5, 5, true);
 static ObjectArray<ScheduledTask> s_oneTimeSchedules(5, 5, true);
-static CONDITION s_cond = ConditionCreate(false);
+static CONDITION s_wakeupCondition = ConditionCreate(false);
 static MUTEX s_cronScheduleLock = MutexCreate();
 static MUTEX s_oneTimeScheduleLock = MutexCreate();
 
 static MUTEX s_cronScheduleLock = MutexCreate();
 static MUTEX s_oneTimeScheduleLock = MutexCreate();
 
@@ -325,7 +325,7 @@ UINT32 AddOneTimeScheduledTask(const TCHAR *task, time_t nextExecutionTime, cons
    s_oneTimeSchedules.add(sh);
    s_oneTimeSchedules.sort(ScheduledTaskComparator);
    MutexUnlock(s_oneTimeScheduleLock);
    s_oneTimeSchedules.add(sh);
    s_oneTimeSchedules.sort(ScheduledTaskComparator);
    MutexUnlock(s_oneTimeScheduleLock);
-   ConditionSet(s_cond);
+   ConditionSet(s_wakeupCondition);
    return RCC_SUCCESS;
 }
 
    return RCC_SUCCESS;
 }
 
@@ -445,7 +445,7 @@ UINT32 UpdateOneTimeScheduledTask(int id, const TCHAR *task, time_t nextExecutio
    }
 
    if(found)
    }
 
    if(found)
-      ConditionSet(s_cond);
+      ConditionSet(s_wakeupCondition);
    return rcc;
 }
 
    return rcc;
 }
 
@@ -514,7 +514,7 @@ UINT32 RemoveScheduledTask(UINT32 id, UINT32 user, UINT64 systemRights)
 
    if (found)
    {
 
    if (found)
    {
-      ConditionSet(s_cond);
+      ConditionSet(s_wakeupCondition);
       DeleteScheduledTaskFromDB(id);
    }
    return rcc;
       DeleteScheduledTaskFromDB(id);
    }
    return rcc;
@@ -643,7 +643,7 @@ static THREAD_RESULT THREAD_CALL OneTimeEventThread(void *arg)
    DbgPrintf(7, _T("OneTimeEventThread: started"));
    while(true)
    {
    DbgPrintf(7, _T("OneTimeEventThread: started"));
    while(true)
    {
-      ConditionWait(s_cond, sleepTime);
+      ConditionWait(s_wakeupCondition, sleepTime);
       if(g_flags & AF_SHUTDOWN)
          break;
 
       if(g_flags & AF_SHUTDOWN)
          break;
 
@@ -780,6 +780,12 @@ static THREAD_RESULT THREAD_CALL CronCheckThread(void *arg)
 }
 
 /**
 }
 
 /**
+ * Scheduler thread handles
+ */
+static THREAD s_oneTimeEventThread = INVALID_THREAD_HANDLE;
+static THREAD s_cronSchedulerThread = INVALID_THREAD_HANDLE;
+
+/**
  * Initialize task scheduler - read all schedules form database and start threads for one time and crom schedules
  */
 void InitializeTaskScheduler()
  * Initialize task scheduler - read all schedules form database and start threads for one time and crom schedules
  */
 void InitializeTaskScheduler()
@@ -809,9 +815,9 @@ void InitializeTaskScheduler()
    }
    DBConnectionPoolReleaseConnection(hdb);
    s_oneTimeSchedules.sort(ScheduledTaskComparator);
    }
    DBConnectionPoolReleaseConnection(hdb);
    s_oneTimeSchedules.sort(ScheduledTaskComparator);
-   //start threads that will start cron and one time tasks threads
-   ThreadCreate(OneTimeEventThread, 0, NULL);
-   ThreadCreate(CronCheckThread, 0, NULL);
+
+   s_oneTimeEventThread = ThreadCreateEx(OneTimeEventThread, 0, NULL);
+   s_cronSchedulerThread = ThreadCreateEx(CronCheckThread, 0, NULL);
 }
 
 /**
 }
 
 /**
@@ -819,9 +825,10 @@ void InitializeTaskScheduler()
  */
 void CloseTaskScheduler()
 {
  */
 void CloseTaskScheduler()
 {
-   ConditionSet(s_cond);
-   ConditionDestroy(s_cond);
-   s_cond = INVALID_CONDITION_HANDLE;
+   ConditionSet(s_wakeupCondition);
+   ThreadJoin(s_oneTimeEventThread);
+   ThreadJoin(s_cronSchedulerThread);
+   ConditionDestroy(s_wakeupCondition);
    ThreadPoolDestroy(g_schedulerThreadPool);
    MutexDestroy(s_cronScheduleLock);
    MutexDestroy(s_oneTimeScheduleLock);
    ThreadPoolDestroy(g_schedulerThreadPool);
    MutexDestroy(s_cronScheduleLock);
    MutexDestroy(s_oneTimeScheduleLock);