2011-11-24 Ramon Novoa <rnovoa@artica.es>

* windows/pandora_wmi.cc: Use double instead of long for intermediate
	  result to avoid overflows. Fixes bug #3422900.

	* modules/pandora_module_perfcounter.cc: Print PDH errors in a more
	  descriptive format.



git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@5167 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
Ramon Novoa 2011-11-24 18:18:14 +00:00
parent d4a8ae4249
commit d4b510c89c
3 changed files with 14 additions and 6 deletions

View File

@ -1,3 +1,11 @@
2011-11-24 Ramon Novoa <rnovoa@artica.es>
* windows/pandora_wmi.cc: Use double instead of long for intermediate
result to avoid overflows. Fixes bug #3422900.
* modules/pandora_module_perfcounter.cc: Print PDH errors in a more
descriptive format.
2011-11-22 Ramon Novoa <rnovoa@artica.es>
* pandora_windows_service.cc: Fixed a bug that resulted in a buffer

View File

@ -129,14 +129,14 @@ Pandora_Module_Perfcounter::run () {
// Open a query object
status = PdhOpenQuery (NULL, 0, &query);
if (status != ERROR_SUCCESS) {
pandoraLog ("PdhOpenQuery failed with error %d", status);
pandoraLog ("PdhOpenQuery failed with error %lX", status);
return;
}
// Add the counter that will provide the data
status = PdhAddCounter (query, this->source.c_str (), 0, &counter);
if (status != ERROR_SUCCESS) {
pandoraLog ("PdhAddCounter failed with error %d", status);
pandoraLog ("PdhAddCounter failed with error %lX", status);
PdhCloseQuery (query);
return;
}

View File

@ -321,7 +321,7 @@ long
Pandora_Wmi::getFreememoryPercent () {
CDhInitialize init;
CDispPtr wmi_svc, quickfixes;
long free_memory, total_memory;
double free_memory, total_memory;
try {
dhCheck (dhGetObject (getWmiStr (L"."), NULL, &wmi_svc));
@ -330,17 +330,17 @@ Pandora_Wmi::getFreememoryPercent () {
L"SELECT FreePhysicalMemory, TotalVisibleMemorySize FROM Win32_OperatingSystem "));
FOR_EACH (quickfix, quickfixes, NULL) {
dhGetValue (L"%d", &free_memory, quickfix,
dhGetValue (L"%e", &free_memory, quickfix,
L".FreePhysicalMemory");
dhGetValue (L"%d", &total_memory, quickfix,
dhGetValue (L"%e", &total_memory, quickfix,
L".TotalVisibleMemorySize");
if (total_memory == 0) {
return 0;
}
return free_memory * 100 / total_memory;
return (long) (free_memory * 100.0 / total_memory);
} NEXT_THROW (quickfix);
} catch (string errstr) {
pandoraLog ("getFreememory error. %s", errstr.c_str ());