diff --git a/plugins/check_disk.cpp b/plugins/check_disk.cpp index aec03c0ac..2ae31b34b 100644 --- a/plugins/check_disk.cpp +++ b/plugins/check_disk.cpp @@ -263,8 +263,8 @@ int printOutput(printInfoStruct& printInfo, vector& vDrives) int check_drives(vector& vDrives) { DWORD dwResult, dwSize = 0, dwVolumePathNamesLen = MAX_PATH + 1; - wchar_t szLogicalDrives[1024], szVolumeName[MAX_PATH], *szVolumePathNames; - HANDLE hVolume; + wchar_t szLogicalDrives[1024], szVolumeName[MAX_PATH], *szVolumePathNames = NULL; + HANDLE hVolume = NULL; wstring wsLogicalDrives; size_t volumeNameEnd = 0; @@ -331,7 +331,8 @@ int check_drives(vector& vDrives) } FindVolumeClose(hVolume); - delete[] reinterpret_cast(szVolumePathNames); + if (szVolumePathNames) + delete[] reinterpret_cast(szVolumePathNames); return -1; die: diff --git a/plugins/check_load.cpp b/plugins/check_load.cpp index 3876b6aa7..33e446a0a 100644 --- a/plugins/check_load.cpp +++ b/plugins/check_load.cpp @@ -199,7 +199,7 @@ int printOutput(printInfoStruct& printInfo) int check_load(printInfoStruct& printInfo) { - PDH_HQUERY phQuery; + PDH_HQUERY phQuery = NULL; PDH_HCOUNTER phCounter; DWORD dwBufferSize = 0; DWORD CounterType; diff --git a/plugins/check_network.cpp b/plugins/check_network.cpp index 30a4ef5aa..075f205b7 100644 --- a/plugins/check_network.cpp +++ b/plugins/check_network.cpp @@ -289,9 +289,12 @@ int check_network(vector & vInterfaces) if (debug) wcout << L"Finished collection. Cleaning up and returning" << endl; - PdhCloseQuery(phQuery); - delete reinterpret_cast(pDisplayValuesIn); - delete reinterpret_cast(pDisplayValuesOut); + if (phQuery) + PdhCloseQuery(phQuery); + if (pDisplayValuesIn) + delete reinterpret_cast(pDisplayValuesIn); + if (pDisplayValuesOut) + delete reinterpret_cast(pDisplayValuesOut); return -1; die: die(err); diff --git a/plugins/check_ping.cpp b/plugins/check_ping.cpp index 258265a46..8c878fc9c 100644 --- a/plugins/check_ping.cpp +++ b/plugins/check_ping.cpp @@ -351,15 +351,17 @@ int check_ping4(const printInfoStruct& pi, response& response) if (debug) wcout << L"All pings sent. Cleaning up and returning" << endl; - IcmpCloseHandle(hIcmp); - delete reinterpret_cast(repBuf); + if (hIcmp) + IcmpCloseHandle(hIcmp); + if (repBuf) + delete reinterpret_cast(repBuf); response.avg = ((double)rtt / pi.num); return -1; die: - die(GetLastError()); + die(); if (hIcmp) IcmpCloseHandle(hIcmp); if (repBuf) @@ -375,6 +377,7 @@ int check_ping6(const printInfoStruct& pi, response& response) IP_OPTION_INFORMATION ipInfo = { 30, 0, 0, 0, NULL }; DWORD dwRepSize = sizeof(ICMPV6_ECHO_REPLY) + 8; LPVOID repBuf = reinterpret_cast(new BYTE[dwRepSize]); + HANDLE hIcmp = NULL; LARGE_INTEGER frequency, timer1, timer2; int num = pi.num; @@ -398,7 +401,7 @@ int check_ping6(const printInfoStruct& pi, response& response) if (debug) wcout << L"Creating Icmp File" << endl; - HANDLE hIcmp = Icmp6CreateFile(); + hIcmp = Icmp6CreateFile(); if (hIcmp == INVALID_HANDLE_VALUE) { goto die; } @@ -450,8 +453,10 @@ int check_ping6(const printInfoStruct& pi, response& response) if (debug) wcout << L"All pings sent. Cleaning up and returning" << endl; - IcmpCloseHandle(hIcmp); - delete reinterpret_cast(repBuf); + if (hIcmp) + IcmpCloseHandle(hIcmp); + if (repBuf) + delete reinterpret_cast(repBuf); response.avg = ((double)rtt / pi.num); return -1; diff --git a/plugins/check_procs.cpp b/plugins/check_procs.cpp index 7a4706be6..c5904eca2 100644 --- a/plugins/check_procs.cpp +++ b/plugins/check_procs.cpp @@ -51,7 +51,7 @@ int wmain(int argc, wchar_t **argv) printInfoStruct printInfo = { }; int r = parseArguments(argc, argv, vm, printInfo); - + if (r != -1) return r; @@ -94,7 +94,7 @@ int parseArguments(int ac, wchar_t **av, po::variables_map& vm, printInfoStruct& std::cout << e.what() << endl << desc << endl; return 3; } - + if (vm.count("help")) { wcout << progName << " Help\n\tVersion: " << VERSION << endl; wprintf( @@ -136,7 +136,7 @@ int parseArguments(int ac, wchar_t **av, po::variables_map& vm, printInfoStruct& cout << endl; return 0; } - + if (vm.count("version")) { std::cout << "Version: " << VERSION << endl; return 0; @@ -208,7 +208,7 @@ int countProcs() if (debug) wcout << L"Counting all processes" << endl; - HANDLE hProcessSnap; + HANDLE hProcessSnap = NULL; PROCESSENTRY32 pe32; if (debug) @@ -240,7 +240,8 @@ int countProcs() if (debug) wcout << L"Found " << numProcs << L" processes. Cleaning up udn returning" << endl; - CloseHandle(hProcessSnap); + if (hProcessSnap) + CloseHandle(hProcessSnap); return numProcs; } diff --git a/plugins/check_swap.cpp b/plugins/check_swap.cpp index 30453ce01..111ad33e4 100644 --- a/plugins/check_swap.cpp +++ b/plugins/check_swap.cpp @@ -36,7 +36,7 @@ static BOOL debug = FALSE; struct printInfoStruct { threshold warn, crit; - DWORD tSwap, aSwap; + double tSwap, aSwap; Bunit unit = BunitMB; }; @@ -210,14 +210,16 @@ int printOutput(printInfoStruct& printInfo) int check_swap(printInfoStruct& printInfo) { - _MEMORYSTATUS *pMemBuf = new _MEMORYSTATUS; + MEMORYSTATUSEX MemBuf; + MemBuf.dwLength = sizeof(MemBuf); - GlobalMemoryStatus(pMemBuf); + if (!GlobalMemoryStatusEx(&MemBuf)) { + die(); + return 3; + } - printInfo.tSwap = round(pMemBuf->dwTotalPageFile / pow(1024.0, printInfo.unit)); - printInfo.aSwap = round(pMemBuf->dwAvailPageFile / pow(1024.0, printInfo.unit)); - - delete pMemBuf; + printInfo.tSwap = round(MemBuf.ullTotalPageFile / pow(1024.0, printInfo.unit)); + printInfo.aSwap = round(MemBuf.ullAvailPageFile / pow(1024.0, printInfo.unit)); return -1; } \ No newline at end of file diff --git a/plugins/check_update.cpp b/plugins/check_update.cpp index c34fc0536..fe1de9217 100644 --- a/plugins/check_update.cpp +++ b/plugins/check_update.cpp @@ -97,7 +97,7 @@ int parseArguments(int ac, wchar_t **av, po::variables_map& vm, printInfoStruct& cout << e.what() << endl << desc << endl; return 3; } - + if (vm.count("help")) { wcout << progName << " Help\n\tVersion: " << VERSION << endl; wprintf( @@ -130,7 +130,7 @@ int parseArguments(int ac, wchar_t **av, po::variables_map& vm, printInfoStruct& , progName, progName); cout << endl; return 0; - } if (vm.count("version")) { + } if (vm.count("version")) { cout << "Version: " << VERSION << endl; return 0; } @@ -190,6 +190,7 @@ int check_update(printInfoStruct& printInfo) ISearchResult *pResult; IUpdateSession *pSession; IUpdateSearcher *pSearcher; + BSTR criteria = NULL; HRESULT err; if (debug) @@ -204,7 +205,7 @@ int check_update(printInfoStruct& printInfo) RebootRequired = 1: Reboot required */ - BSTR criteria = SysAllocString(CRITERIA); + criteria = SysAllocString(CRITERIA); // http://msdn.microsoft.com/en-us/library/windows/desktop/aa386526%28v=vs.85%29.aspx // http://msdn.microsoft.com/en-us/library/ff357803%28v=vs.85%29.aspx diff --git a/plugins/check_uptime.cpp b/plugins/check_uptime.cpp index e6255b88d..37606a54c 100644 --- a/plugins/check_uptime.cpp +++ b/plugins/check_uptime.cpp @@ -171,7 +171,7 @@ int parseArguments(int ac, wchar_t **av, po::variables_map& vm, printInfoStruct& if (vm.count("debug")) debug = TRUE; - + return -1; }