landrix / The-Drag-and-Drop-Component-Suite-for-Delphi

MIT License
161 stars 57 forks source link

Evicense of "Use after free" #61

Closed GabrielOnDelphi closed 1 year ago

GabrielOnDelphi commented 1 year ago

Replace in DragDrop.pas this code:

finalization DragDropShutdown := True; // Note: Due to unit finalization order, is is possible for the following two // objects to be recreated after this units' finalization has executed. // If that happens it will result in a harmless one-time memory leak. if (FDataFormatMap <> nil) then FDataFormatMap.Free; if (FDataFormatClasses <> nil) then FDataFormatClasses.Free;

with this code:

finalization DragDropShutdown := True; // Note: Due to unit finalization order, is is possible for the following two // objects to be recreated after this units' finalization has executed. // If that happens it will result in a harmless one-time memory leak.

FreeAndNil(FDataFormatMap); FreeAndNil(FDataFormatClasses);


In theory is the same. If my code is used hoever, there will be an assertion failure when you install the package.

DragDropDR104R - Delphi 10.4 - DragDrop [Built] Assertion failure (DragDrop.pas, line 1661)

This is a clear indicate on free after use!

GabrielOnDelphi commented 1 year ago

At that point the FDataFormatMap is nil:

ASSERT((FDataFormatMap = NIL) OR (FDataFormatMap = Self), 'Adr: '+ IntToStr(Integer(FDataFormatMap)) );