JP Guest
|
Posted: Thu Feb 26, 2004 1:38 pm Post subject: Is there a memory leak in this code? |
|
|
Hi, I have a program that creates a thread and that new thread calls
this bit of code on a regular interval. It looks like it is leaking
memory, does anyone see anything wrong with this code?
function WatchService(oService: TServiceObject): string;
var
schm, schs: SC_Handle;
ss: TServiceStatus;
psTemp: PChar;
iErr: integer;
begin
ss.dwCurrentState := 0;
// connect to the service control manager
schm := OpenSCManager(PChar(oService.GetServer), nil,
GENERIC_READ);
// if successful...
if (schm > 0) then
begin
// open a handle to the specified service
schs := OpenService(schm, PChar(oService.GetName),
SERVICE_QUERY_STATUS or SERVICE_START);
// check status
if (QueryServiceStatus(schs, ss)) then
begin
if ss.dwCurrentState = SERVICE_STOPPED then
begin
if oService.Restart = true then
begin
StartService(schs, 0, psTemp);
end;
end;
end;
//close service handle
CloseServiceHandle(schs);
end;
if(schs = 0) or (schm = 0) then
begin
iErr := GetLastError;
Result := SysErrorMessage(iErr);
exit;
end;
// close service control manager handle
CloseServiceHandle(schm);
// return TRUE if the service status is running
QueryServiceStatus(schs, ss);
if SERVICE_RUNNING = ss.dwCurrentState then
Result := 'Running'
else
begin
Result := 'Stopped';
end;
end;
end.
Thanks,
JP
|
|