在伤透脑筋两天后,我放弃了独自解决这个问题。
我目前正在开发一个服务,该服务需要检查某些其他服务的配置,以决定是否可以继续执行程序的其余部分。
到目前为止,一切都很好,它正在发挥作用,但记忆的清理似乎有问题。GetMem()
和FreeMem()
似乎并没有真正归还内存,而New()
和Dispose()
似乎在内部破坏了内存分配。
function tServiceStoppStart.GetServiceConfigStartTtype(sService: String): DWORD;
var
schm, schs: SC_Handle;
config: LPQUERY_SERVICE_CONFIG;
pcbBytesNeeded: DWORD;
sucessful: boolean;
begin
try
try
begin
sucessful := false;
// open the service manager (defined in WinSvc)
schm := OpenSCManager(nil, nil, SC_MANAGER_ALL_ACCESS);
if (schm > 0) then
begin
// grab the service handle
schs := OpenService(schm, PChar(sService), SERVICE_ALL_ACCESS);
if (schs > 0) then
begin
// get the byte count for the serviceconfig query
//over the pcbBytesNeeded witchz is filled with the right amount after 1. call
QueryServiceConfig(schs, config, 0, pcbBytesNeeded);
// 1. GetMem(config, pcbBytesNeeded);
// 2. New(config); -> seems to corrupt the memory allocation
if QueryServiceConfig(schs, config, pcbBytesNeeded, pcbBytesNeeded) then
begin
Result := config.dwStartType;
sucessful := True;
end;
end;
end;
CloseServiceHandle(schs);
end;
except
on E: Exception do
begin
//
end;
end;
finally
begin;
if sucessful then
begin
// seems not to free the memory
// 1. freeMem(config,pcbBytesNeeded)
// 2. Dispose(config) -> seems to corrupt the memory allocation
end;
end;
end;
end;
{Set the new first free block}
mov TSmallBlockPoolHeader[edx].FirstFreeBlock, ecx
{Set the block header} // gets accesviolation with new and dispose
mov [eax - 4], edx
{Is the chunk now full?}
jz @RemoveSmallPool
通过对象创建调用
我对自己在德尔福的记录处理没有那么自信。有人能给我指正确的方向吗?
看起来它已经修复了,尽管管理器的关闭导致管理器打开垃圾邮件thx J…以提示关闭