Page 1 of 1

Memory allocation problems with 2.40.13

Posted: Mon 24 Nov 2008 15:16
by Sieg
I encountered a strange problem. I tried to check for memory leaks in our application server, so I enabled FullDebugMode on FastMM4 (4.90). It reported "double free" whenever I tried to check if a date field is null. Server is Firebird 2.1.1.
I created a very simple test app with a single query, code is like this:

Code: Select all

var
  q: TSQLQuery;
begin
  q := TSQLQuery.Create(nil);
  try
    q.SQLConnection := SQLConnection1;
    q.SQL.Text := 'select datum from route';
    q.Open;
    while not q.Eof do begin
      if q.Fields[0].IsNull then
        q := q;  // dummy
      q.Next;
    end;
  finally
    q.Free;
  end;
end;
The stack trace of the FastMM4 report:

Code: Select all

FastMM has detected an error during a FreeMem operation. The block footer has been corrupted. 

The block size is: 4

This block was allocated by thread 0x6D8, and the stack trace (return addresses) at the time was:
40ACB6 [FastMM4.pas][FastMM4][DebugAllocMem][6617]
40315A [sys\system.pas][System][AllocMem][2552]
48718F [DB.pas][DB][TDataSet.GetFieldData][9627]
47C3C2 [DB.pas][DB][TField.GetData][3873]
47C5BE [DB.pas][DB][TField.GetIsNull][3980]
44A68A [Controls.pas][Controls][TControl.Click][5229]
...

The block is currently used for an object of class: Unknown

The allocation number is: 7352

The block was previously freed by thread 0x6D8, and the stack trace (return addresses) at the time was:
40318E [sys\system.pas][System][@FreeMem][2699]

The current thread ID is 0x6D8, and the stack trace (return addresses) leading to this error is:
40318E [sys\system.pas][System][@FreeMem][2699]
48718F [DB.pas][DB][TDataSet.GetFieldData][9627]
47C3C2 [DB.pas][DB][TField.GetData][3873]
47C5BE [DB.pas][DB][TField.GetIsNull][3980]
44A68A [Controls.pas][Controls][TControl.Click][5229]
...
The field or table in the query does not matter as long as it is of type date. Other types do not produce the error.
I crosschecked it with the "stock" Codegear Interbase driver and that does not produce the error.

Any ideas what can cause this or any possible workarounds to avoid it?

Posted: Tue 25 Nov 2008 10:26
by Plash
We have fixed this problem. The fix will be included in the next build of DbxIda.