Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Dynamic memory allocation causes system crash on Win98?

Mike85Mike85 Posts: 61Member
[b][red]This message was edited by Mike85 at 2003-7-15 13:9:35[/red][/b][hr]
Hi!

I have this strange problem when I run my program on Windows 98. Windows totally freezes, only the cursor moves and when ctrl+alt+del is pressed there comes the "sadly infamous" blue screen saying that "system is busy" and please wait a while. However the reset is only solution to bring windows back running again. The crash seem to occur always on the line on specific procedure which calls Delphi's "New"-procedure to initialize variable holding directory entry. The DirEnt itself is only 32 bytes and there is plenty of RAM availbale to it can't be that windows have run out of memory.

Cause I can't debug the program on Windows 98 machine I added message boxes between each line to indicate what's going on, and the New definetly seem to cause crash. I first thought that problem is on low level disk reading system or somewhere else cause program runs perfectly on Windows 2000 and XP, but the disk sector reading and other stuff works fine, until it comes to this procedure.

Directory entries are allocated dynamically so they can be associated with each TListItem's Data property and they will be deallocated in Form's OnDestroy.

[code]
procedure TFAT32BrowseForm.ReadDirectory(Clust: Cardinal);
var
M: TMemoryStream;
DirEnt: pFAT32DirEntry;
Item: TListItem;
FileName: string;
begin
View.Clear;
if Clust > 1 then
CurClust := Clust
else
CurClust := FAT32.BootSec.RootDirStartClust;
M := FAT32.ReadClusterChain(CurClust);
repeat
New(DirEnt); // <- crash!!!
M.ReadBuffer(DirEnt^,SizeOf(TFAT32DirEntry));
if Byte(DirEnt.Attributes) = $0F then
FileName := FAT32LongFilename(DirEnt^,M)
else
FileName := FAT32ShortFilename(DirEnt^);
if (DirEnt.FileName[0] in [#0]) then
begin
Dispose(DirEnt);
Continue;
end;
Item := View.Items.Add;
if DirEnt.FileName[0] = #229 then
begin
if FileName[1] = #229 then FileName[1] := '?';
Item.Caption := FileName;
if aDirectory in DirEnt.Attributes then
Item.ImageIndex := 3 else
Item.ImageIndex := 2;
Item.Data := DirEnt;
end
else
begin
Item.Caption := FileName;
if aDirectory in DirEnt.Attributes then
Item.ImageIndex := 0 else
Item.ImageIndex := 1;
Item.Data := DirEnt;
end;
until M.Size - M.Position <= 32;
M.Free;
end;
[/code]


Comments

  • ManningManning Posts: 1,621Member
    : I have this strange problem when I run my program on Windows 98. Windows totally freezes, only the cursor moves and when ctrl+alt+del is pressed there comes the "sadly infamous" blue screen saying that "system is busy" and please wait a while. However the reset is only solution to bring windows back running again. The crash seem to occur always on the line on specific procedure which calls Delphi's "New"-procedure to initialize variable holding directory entry. The DirEnt itself is only 32 bytes and there is plenty of RAM availbale to it can't be that windows have run out of memory.


    Does it happen the very first time through the loop, or only after at least 1 iteration? If it happens the very first time through I dont know what's wrong. But if it's OK the first time and crashes after that, it's probably because you dont Dispose() of it in all cases. So you New() it, then when you get to the top of the loop you New() it again before Dispose()ing it.
  • Mike85Mike85 Posts: 61Member
    I got it fixed now after hours of debugging. I had to install Delphi 7 on the Win98 machine with 32 MB ram, what a nightmare. Anyway the problem was not in new memory allocation though. The VxD I/O driver I was using on Win98 causes crash each time when more than 4 sectors are read from disk. I changed the disk reading routines so that they read always 4 sectors max, per each DeviceIoContol call. The crash happens a bit delayed after reading so it looked like the "New" was causing it.
Sign In or Register to comment.