Plug various handle+mem leaks on win32
Submitted by: Jan Kneschke <jan.kneschke@mysql.com>
This commit is contained in:
parent
795db98647
commit
1affc51534
|
@ -1,3 +1,8 @@
|
|||
2007-03-07 Doug MacEachern <dougm@hyperic.com>
|
||||
|
||||
* Plug various handle+mem leaks on win32
|
||||
Submitted by: Jan Kneschke <jan.kneschke@mysql.com>
|
||||
|
||||
2007-02-24 Doug MacEachern <dougm@hyperic.com>
|
||||
|
||||
* Make Java objects returned by Sigar class Serializable
|
||||
|
|
|
@ -198,6 +198,7 @@ static unsigned char CPUCount(unsigned char *LogicalNum,
|
|||
if (dwProcessAffinity != dwSystemAffinity) {
|
||||
StatusFlag = HT_CANNOT_DETECT;
|
||||
// *PhysicalNum = (unsigned char)-1;
|
||||
CloseHandle(hCurrentProcessHandle);
|
||||
return StatusFlag;
|
||||
}
|
||||
|
||||
|
@ -244,6 +245,7 @@ static unsigned char CPUCount(unsigned char *LogicalNum,
|
|||
StatusFlag = HT_SUPPORTED_NOT_ENABLED;
|
||||
}
|
||||
}
|
||||
CloseHandle(hCurrentProcessHandle);
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
@ -299,11 +301,13 @@ int sigar_cpu_info_get(sigar_t *sigar, sigar_cpu_info_t *info)
|
|||
//just lookup the first id, then assume all cpus are the same.
|
||||
rc = RegEnumKey(key, 0, id, sizeof(id));
|
||||
if (rc != ERROR_SUCCESS) {
|
||||
RegCloseKey(key);
|
||||
return rc;
|
||||
}
|
||||
|
||||
rc = RegOpenKey(key, id, &cpu);
|
||||
if (rc != ERROR_SUCCESS) {
|
||||
RegCloseKey(key);
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
@ -343,6 +347,8 @@ int sigar_cpu_info_get(sigar_t *sigar, sigar_cpu_info_t *info)
|
|||
}
|
||||
|
||||
info->cache_size = -1; //XXX
|
||||
RegCloseKey(key);
|
||||
RegCloseKey(cpu);
|
||||
|
||||
return SIGAR_OK;
|
||||
}
|
||||
|
|
|
@ -1108,6 +1108,7 @@ SIGAR_DECLARE(int) sigar_proc_time_get(sigar_t *sigar, sigar_pid_t pid,
|
|||
{
|
||||
HANDLE proc = open_process(pid);
|
||||
FILETIME start_time, exit_time, system_time, user_time;
|
||||
int status = ERROR_SUCCESS;
|
||||
|
||||
if (!proc) {
|
||||
return GetLastError();
|
||||
|
@ -1117,11 +1118,15 @@ SIGAR_DECLARE(int) sigar_proc_time_get(sigar_t *sigar, sigar_pid_t pid,
|
|||
&start_time, &exit_time,
|
||||
&system_time, &user_time))
|
||||
{
|
||||
return GetLastError();
|
||||
status = GetLastError();
|
||||
}
|
||||
|
||||
CloseHandle(proc);
|
||||
|
||||
if (status != ERROR_SUCCESS) {
|
||||
return status;
|
||||
}
|
||||
|
||||
if (start_time.dwHighDateTime) {
|
||||
proctime->start_time = FileTimeToTime(&start_time) / 1000;
|
||||
}
|
||||
|
@ -1347,6 +1352,7 @@ static int sigar_remote_proc_env_get(sigar_t *sigar, sigar_pid_t pid,
|
|||
char *value;
|
||||
DWORD rv, thrid, bytes, datalen=0, size;
|
||||
LPVOID addr;
|
||||
int status;
|
||||
|
||||
if (!(kdll = GetModuleHandle("msvcrt.dll"))) {
|
||||
return GetLastError();
|
||||
|
@ -1364,6 +1370,8 @@ static int sigar_remote_proc_env_get(sigar_t *sigar, sigar_pid_t pid,
|
|||
return GetLastError();
|
||||
}
|
||||
|
||||
/* FIXME: close the kdll handles */
|
||||
|
||||
if (!(proc = OpenProcess(MAXIMUM_ALLOWED, 0, (DWORD)pid))) {
|
||||
return GetLastError();
|
||||
}
|
||||
|
@ -1435,15 +1443,16 @@ static int sigar_remote_proc_env_get(sigar_t *sigar, sigar_pid_t pid,
|
|||
key, strlen(key),
|
||||
value, bytes-1);
|
||||
|
||||
HeapFree(GetProcessHeap(), 0, value);
|
||||
status = SIGAR_OK;
|
||||
}
|
||||
else {
|
||||
CloseHandle(proc);
|
||||
return GetLastError();
|
||||
status = GetLastError();
|
||||
}
|
||||
|
||||
HeapFree(GetProcessHeap(), 0, value);
|
||||
CloseHandle(proc);
|
||||
return SIGAR_OK;
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
SIGAR_DECLARE(int) sigar_proc_env_get(sigar_t *sigar, sigar_pid_t pid,
|
||||
|
@ -1533,6 +1542,8 @@ SIGAR_DECLARE(int) sigar_proc_exe_get(sigar_t *sigar, sigar_pid_t pid,
|
|||
procexe->name[0] = toupper(procexe->name[0]);
|
||||
}
|
||||
|
||||
CloseHandle(proc);
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue