内存在Windows服务配置上泄漏或损坏

发布于 2025-01-21 00:10:25 字数 2096 浏览 0 评论 0原文

两天后,我放弃了自己解决这个问题。

目前,我正在开发一项需要检查某些其他服务的配置以决定是否可以继续进行程序的服务。

到目前为止,一切都很好,但是清理记忆似乎是错误的。 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

ゃ人海孤独症 2025-01-28 00:10:25

看来已经解决了经理的关闭,这使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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文