内存在Windows服务配置上泄漏或损坏
两天后,我放弃了自己解决这个问题。
目前,我正在开发一项需要检查某些其他服务的配置以决定是否可以继续进行程序的服务。
到目前为止,一切都很好,但是清理记忆似乎是错误的。 getMem()
和freemem()
似乎并没有真正退还内存,new()
and 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
通过对象创建电话,
我对在Delphi的记录处理并不那么自信。有人可以将我指向正确的方向吗?
After 2 days wracking my brain, I give up on fixing this problem on my own.
I'm currently working on a service that needs to check the config of certain other services to decide if it can proceed with the rest of the program.
So far so good, it is working, but the clean up of the memory seems to be faulty. GetMem()
and FreeMem()
seem not to really give back the memory, and New()
and Dispose()
seem to break the memory allocation internally.
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
by object create calls
I'm not that confident in my record handling in Delphi. Can someone point me in the right direction?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看来已经解决了经理的关闭,这使Meomry泄漏了MALID,经理通过经理打开垃圾邮件j ...用于关闭的提示
Looks like it got fixed thoug the closing of the manager proably got meomry leak from build up by manager opening spam thx J... for the cue for the close