Access Violation while TOraSQL freeing

Discussion of open issues, suggestions and bugs regarding ODAC (Oracle Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
Traptak
Posts: 26
Joined: Fri 29 Jun 2007 07:15

Access Violation while TOraSQL freeing

Post by Traptak » Tue 14 Jan 2014 15:24

Hello,

I have next problem with ODAC 9.2.5. The problem is with code which looks like that:

Code: Select all

  OraSession1.Connect;
  FOraSQL := TOraSQL.Create(Self);
  FOraSQL.SQL.Text := 'select * from v$session where sid = :sid';
  FOraSQL.Params[0].DataType := TFieldType(107);  // Number
  FOraSQL.Prepare;
  FOraSQL.Session := OraSession2;
  FOraSQL.Free;  // <--- Access Violation here
When I try to free FOraSQL instance then Access Violation is raised. I think the problem is with TOraNumber class. The exception is raised in TOraNumber destructor:

Code: Select all

destructor TOraNumber.Destroy;
begin
  Marshal.FreeHGlobal(FIndicator);
  if FHandleType <> htShared then //To support SetOCINumberPtr assignation
    Marshal.FreeHGlobal(phOCINumber);

  if FHandleType <> htLocal then begin
  {$IFNDEF AUTOREFCOUNT}
    FEnvironment.ReleaseRef;  // <-- Exactly here is raised exception
When Session property for TOraSQL instance is changed then FEnvironment field is set to nil. But in TOraSQL's destructor value of FEnvironment field is not checked. And in this case the exception while freeing is raised. I think the source of problem is in TOraNumber.SetEnvironment procedure:

Code: Select all

  if FEnvironment <> AEnvironment then begin
  {$IFNDEF AUTOREFCOUNT}
    if FEnvironment <> nil then
      FEnvironment.ReleaseRef;
  {$ENDIF}
    FEnvironment := AEnvironment;
  {$IFNDEF AUTOREFCOUNT}
    if FEnvironment <> nil then
      FEnvironment.AddRef;
  {$ENDIF}
  end;
I think it should be similar to the procedure TOraInterval.SetEnvironment and looks like:

Code: Select all

  if FEnvironment <> AEnvironment then begin
  {$IFNDEF AUTOREFCOUNT}
    if FEnvironment <> nil then
      FEnvironment.ReleaseRef;
  {$ENDIF}
    FEnvironment := AEnvironment;
    if FEnvironment <> nil then 
    begin
      FHandleType := htNative;
      {$IFNDEF AUTOREFCOUNT}
        FEnvironment.AddRef;
      {$ENDIF}
    end
    else
      FHandleType := htLocal;
  end;
After this correction my code works without exceptions. :D

AlexP
Devart Team
Posts: 5530
Joined: Tue 10 Aug 2010 11:35

Re: Access Violation while TOraSQL freeing

Post by AlexP » Wed 15 Jan 2014 10:46

Hello,

Thank you for the information. We have added the required modifications to solve the problem. These modifications will be included in the next version.

Post Reply