fixed memory leaks in Linux agent (backported from 1.0.x)
authorVictor Kirhenshtein <victor@netxms.org>
Sat, 3 Apr 2010 22:12:57 +0000 (22:12 +0000)
committerVictor Kirhenshtein <victor@netxms.org>
Sat, 3 Apr 2010 22:12:57 +0000 (22:12 +0000)
src/agent/subagents/linux/iostat.cpp
src/agent/subagents/linux/proc.cpp
src/agent/subagents/sunos/process.cpp
src/libnetxms/config.cpp
tools/create_bin_apkg.sh

index 122b415..2ce58d1 100644 (file)
@@ -110,7 +110,7 @@ static void ParseIoStat(char *line)
                strcpy(m_devices[dev].name, devName);
                m_devices[dev].isRealDevice = IsRealDevice(devName);
                memset(m_devices[dev].samples, 0, sizeof(IOSTAT_SAMPLE) * SAMPLES_PER_MINUTE);
-               AgentWriteLog(EVENTLOG_DEBUG_TYPE, "ParseIoStat(): new device added (name=%s isRealDevice=%d)", devName, m_devices[dev].isRealDevice);
+               AgentWriteDebugLog(2, "ParseIoStat(): new device added (name=%s isRealDevice=%d)", devName, m_devices[dev].isRealDevice);
        }
 
        // Parse counters
@@ -191,7 +191,7 @@ void StartIoStatCollector()
                if (S_ISDIR(st.st_mode))
                {
                        m_isSysFsAvailable = true;
-                       AgentWriteLog(EVENTLOG_DEBUG_TYPE, "Linux: using /sys/block to distinguish devices from partitions");
+                       AgentWriteDebugLog(2, "Linux: using /sys/block to distinguish devices from partitions");
                }
        }       
 
index 110bf35..af6f615 100644 (file)
@@ -72,7 +72,9 @@ int ProcRead(PROC_ENT **pEnt, char *szProcName, char *szCmdLine)
        BOOL bProcFound, bCmdFound;
 
        nFound = -1;
-       AgentWriteLog(EVENTLOG_DEBUG_TYPE, "ProcRead(%p,\"%s\",\"%s\")", pEnt, CHECK_NULL(szProcName), CHECK_NULL(szCmdLine));
+       if (pEnt != NULL)
+               *pEnt = NULL;
+       AgentWriteDebugLog(5, "ProcRead(%p,\"%s\",\"%s\")", pEnt, CHECK_NULL(szProcName), CHECK_NULL(szCmdLine));
 
        nCount = scandir("/proc", &pNameList, &ProcFilter, alphasort);
        // if everything is null we can simply return nCount!!!
@@ -222,7 +224,7 @@ int ProcRead(PROC_ENT **pEnt, char *szProcName, char *szCmdLine)
                                                           &(*pEnt)[nFound].utime, &(*pEnt)[nFound].ktime, &(*pEnt)[nFound].threads,
                                                           &(*pEnt)[nFound].vmsize, &(*pEnt)[nFound].rss) != 10)
                                                {
-                                                       AgentWriteLog(EVENTLOG_DEBUG_TYPE, "Error parsing /proc/%d/stat", nPid);
+                                                       AgentWriteDebugLog(2, "Error parsing /proc/%d/stat", nPid);
                                                }
                                        }
                                }
@@ -234,6 +236,12 @@ int ProcRead(PROC_ENT **pEnt, char *szProcName, char *szCmdLine)
                free(pNameList);
        }
 
+       if ((nFound < 0) && (pEnt != NULL))
+       {
+               safe_free(*pEnt);
+               *pEnt = NULL;
+       }
+
        return nFound;
 }
 
@@ -285,6 +293,7 @@ LONG H_ThreadCount(const char *param, const char *arg, char *value)
                        sum += procList[i].threads;
                ret_int(value, sum);
                ret = SYSINFO_RC_SUCCESS;
+               free(procList);
        }
 
        return ret;
@@ -337,7 +346,7 @@ LONG H_ProcessDetails(const char *param, const char *arg, char *value)
        StrStrip(cmdLine);
 
        count = ProcRead(&procList, procName, (cmdLine[0] != 0) ? cmdLine : NULL);
-       AgentWriteLog(EVENTLOG_DEBUG_TYPE, "H_ProcessDetails(\"%s\"): ProcRead() returns %d", param, count);
+       AgentWriteDebugLog(5, "H_ProcessDetails(\"%s\"): ProcRead() returns %d", param, count);
        if (count == -1)
                return SYSINFO_RC_ERROR;
 
index 45e7275..05646bc 100644 (file)
@@ -156,6 +156,11 @@ static int ProcRead(PROC_ENT **pEnt, char *pszProcName, char *pszCmdLine)
                free(pNameList);
        }
 
+       if ((nFound < 0) && (pEnt != NULL))
+       {
+               safe_free(*pEnt);
+               *pEnt = NULL;
+       }
        return nFound;
 }
 
@@ -441,18 +446,7 @@ LONG H_ProcessInfo(const char *param, const char *arg, char *value)
                        nRet = SYSINFO_RC_SUCCESS;
                }
        }
+       safe_free(pList);
 
        return nRet;
 }
-
-///////////////////////////////////////////////////////////////////////////////
-/*
-
-$Log: not supported by cvs2svn $
-Revision 1.9  2006/05/15 22:11:22  alk
-+ Net.Interface.Link() workaround; trying kstat() first, then
-IFF_RUNNING it kstat's link_up failed.
-- code reformated
-
-
-*/
index 558fcd8..da83dcb 100644 (file)
@@ -59,6 +59,7 @@ ConfigEntry::~ConfigEntry()
                delete entry;
        }
        safe_free(m_name);
+       safe_free(m_file);
 
        for(int i = 0; i < m_valueCount; i++)
                safe_free(m_values[i]);
index e9ac15e..c0c4015 100755 (executable)
@@ -24,7 +24,7 @@ fi
 
 currdir=`pwd`
 cd $prefix &&
-tar cvf nxagent-binary.tar * &&
+tar cvf nxagent-binary.tar bin/ lib/ &&
 gzip nxagent-binary.tar &&
 cd $currdir &&
 rm -rf inst &&