delphi - "Invalid address specified to RtlFreeHeap( 06450000, 08387460 )"是什么意思?

标签 delphi debugging dll heap-memory

有时我的 Delphi 程序会随机崩溃。我的程序停止,调试器输出:

指定给 RtlFreeHeap( 06450000, 08387460 ) 的地址无效

这是什么意思?什么可能导致它?

这是 CPU Inspector 停止的地方:

77BA0845 C6052582BD7700 mov byte ptr [$77bd8225],$00

请注意,它们是非常随机的(对我来说)。有时它们根本不出现。

我正在使用 Skype 的 Skype4COM.dll - 但没有来源。

如果您需要它,这里是代码。我已经评论了大多数对 Synchronize 的调用,因此您知道它们的作用。

////////////////////////////////////////////////////////////////////////////////
/// Execute
////////////////////////////////////////////////////////////////////////////////
procedure TContactDeletor.Execute;
Var
  I             : Integer;
  UserObj       : PUser;
  User          : IUser;
  PauseEvent    : TEvent;
begin
  inherited;
  FreeOnTerminate       := True;
  if Terminated then
  Exit;

  CoInitialize(Nil);
  // The F-Flags are to make sure TSkype events do not fire (from my Main Thread)
  FAllowUI              := False;
  FUserIsBeingDeleted   := False;
  FUseGroupUsersEvent   := False;
  FUseRenameEvent       := False;
  SkypeThr              := TSkype.Create(Nil);
  SkypeThr.Attach(10,False);
  SkypeThr.Cache        := False;
  MyList                := TStringList.Create;
  PauseEvent            := TEvent.Create(True);
  try
  // This fills my Stringlist
  Synchronize(GrabList);
  if Terminated then Exit;


  iMax                  := MyList.Count;
  // This sets the Max of my Progressbar
  Synchronize(SetMax);
  Try
  for I := 0 to MyList.Count - 1 do
    begin

      {while SkypeThr.AttachmentStatus <> apiAttachSuccess do
      begin
        SkypeThr.Attach(10,False);
        Synchronize(Procedure Begin Log('Skype Unavailable - Trying to reconnect ...'); End);
        PauseEvent.WaitFor(5000);
      end;  }

      CurUser := '';
      User := SkypeThr.User[MyList[I]];
      CurUser := MyList[I];

      Try
      User.IsAuthorized := False;
      User.BuddyStatus := budDeletedFriend;
      Except on E:Exception do
      begin
       ExErr := E.Message;
       ExLog := 'Error while deleting contacts: ';
       ExMsg := 'An Error has occured while deleting contacts: ';
       Synchronize(
       Procedure
       Begin
        Log(ExLog+ExErr+sLineBreak+' - Last logged Handle: '+CurUser);
       End
       );    
      end;
      end;

      iProgress := I+1;
      // This updates my log and my progressbar.
      Synchronize(UpdatePG);
      PauseEvent.WaitFor(100);

      if (I mod 200 = 0) and (I > 0) then
        begin
          // Calls to Synchronize updates my log
          Synchronize(SyncPauseBegin);
          PauseEvent.WaitFor(3000);
          Synchronize(SyncPauseEnd);
        end;


    end;
  // Except
  Except on E:Exception do
  begin
   ExErr := E.Message;
   ExLog := 'Error while deleting contacts: ';
   ExMsg := 'An Error has occured while deleting contacts: ';
   Synchronize(
   Procedure
   Begin
    Log(ExMsg+ExErr+sLineBreak+' - Last logged Handle: '+CurUser);
    ErrMsg(ExMsg+ExErr+sLineBreak+sLineBreak+' - Last logged Handle: '+CurUser);
   End
   );
   Exit;
  end;
  end;
  // This synchronizes my visual list.
  Synchronize(SyncList);
  finally
   FUserIsBeingDeleted   := False;
   FUseGroupUsersEvent   := True;
   FUseRenameEvent       := True;
   FAllowUI              := True;
   Synchronize(
   Procedure
   Begin
   frmMain.UpdateStatusBar;
   PleaseWait(False);
   ToggleUI(True);
   end);
   PauseEvent.Free;
   SkypeThr.Free;
   MyList.Free;
   CoUninitialize;
  end;


end;

最佳答案

Najem 是正确的,这是因为你的堆已损坏。为了更容易调试,您应该启用 PageHeap另外,尽可能多地使用调试 CRT(或调试 delphi 运行时),直到找出是什么破坏了您的内存。

很多时候,损坏可能只会溢出几个字节。然后您的应用程序可以在很长一段时间内正常运行,因此您直到很久以后才会注意到任何错误(如果有的话)。

当您寻找内存损坏错误时,请尝试干净地退出您的应用程序,不要只是停止调试器,当您的进程退出时,它应该“触及”之前分配的大部分内存,这样您就有机会检测到失败。

关于delphi - "Invalid address specified to RtlFreeHeap( 06450000, 08387460 )"是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5608323/

相关文章:

delphi - 为什么这段代码只运行了两次

delphi - 我需要在 Delphi 中免费 IDispatch

c++ - 如何在多显示器设置中测试我的 Windows 应用程序?

java - 远程监控所有 Android 设备事件

c++ - windows下建vst时如何使用外部dll

java - Tomcat 无法识别 DLL 文件

delphi - 是否有适用于 Delphi(非 OLE)的 OpenOffice.org 导出组件?

delphi - 当应用程序有很多数据集时如何整理表单

debugging - 如何在 Haskell 中获取调用堆栈?

c# - 方法重写或拦截