BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Is there a memory leak in this code?

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi WinAPI
View previous topic :: View next topic  
Author Message
JP
Guest





PostPosted: Thu Feb 26, 2004 1:38 pm    Post subject: Is there a memory leak in this code? Reply with quote



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
Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi WinAPI All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.