Search code examples
oracledelphiblobdelphi-xe7bde

Delphi BDE with connection to Oracle access violation


I'm searching for a bug in a big legacy product. The end user only reports a program crash (no error messages). When I start the program with attached debugger I get this:

Im Projekt XXXXX.exe ist eine Exception der Klasse $C0000005 mit der Meldung 'access violation at 0x00000000: read of address 0x00000000' aufgetreten.

When I look at the stack trace the error happened here:

procedure TQuery.FreeStatement;
var
  Result: DbiResult;
begin
  if StmtHandle <> nil then
  begin
    Result := DbiQFree(FStmtHandle);
    if not (csDestroying in ComponentState) then
      Check(Result);
  end;
end;

The AV happens at the Result := DbiQFree(FStmtHandle); line.

It is triggered by a call to TQuery.Close. The TQuery object in question is used for Select statements. I can't figure out where the nil pointer is located. I already used FastMM4 with FullDebugMode to find if there is any use after free or other stuff. But FastMM4 don't reports anything erroneous. I also recompiled the Project with enabled madExcept but madExcept also can't catch the error (program simply closes when no Debugger is connected).

I attached an OnDisconnect and OnConnect event handler to the TDatabase object. At the time of the error the connection is not disconnected according to the events.

Does anyone have an idea where the error can be located? Also any software or debugging tip to get closer to the potential erroneous pice of code is helpful ;-)


Solution

  • The SQL Statement executed by the TQuery Object prior to the Close call was an Select * ... statement. The Query returned several Columns one of them was a RAW aka BLOB Column. The Content of the Columns was maybe too big to handle it. After reviewing the Code and checking that the RAW Column Data is not used at all instead the query is only used to check if there is data in the Table. I changed the Query to Select 1 ... the Problem is fixed. So, for everyone having same strange error. Check the resulting data set for RAW columns. Even when the returned Row has a NULL Value in the given Column.