ghkweon / dwscript

Automatically exported from code.google.com/p/dwscript
0 stars 0 forks source link

Memory corruption in DWSJson #375

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?

IMPORTANT: Make sure to build this with FastMM4's FullDebugMode enabled

procedure test;
var value: TdwsJSONValue;
begin
   value := TdwsJSONValue.ParseString('0');
   value.Free;
end;

Expected: It should work
Observed: In the Free operation, FastMM raises a memory corruption error.

The error appears to be related to TClassCloneConstructor, as replacing the 
body of the Create method with the following gets rid of the error:

function TClassCloneConstructor<T>.Create : T;
begin
   GetMem(pointer(TObject(result)), FSize);
   System.Move(Pointer(TObject(FTemplate))^, Pointer(TObject(Result))^, FSize);
end;

Original issue reported on code.google.com by masonwhe...@gmail.com on 21 Apr 2013 at 8:34

GoogleCodeExporter commented 8 years ago
This issue was closed by revision r1953.

Original comment by zar...@gmail.com on 22 Apr 2013 at 6:05

GoogleCodeExporter commented 8 years ago
Issue with generics codegen or with FullDebugMode preamble/postamble padding?

Original comment by zar...@gmail.com on 22 Apr 2013 at 6:06

GoogleCodeExporter commented 8 years ago
Looking at this further, it appears to be the latter, sort of.  SysGetMem calls 
into the GetMem.inc supplied with the RTL, instead of the currently installed 
memory manager, which means the FullDebugMode padding is never added.  Then you 
go to free things, and it doesn't find this padding, and raises a memory 
corruption error.

Original comment by masonwhe...@gmail.com on 22 Apr 2013 at 2:49