Page 1 of 1

Access Violation while TOraSQL freeing

Posted: Tue 14 Jan 2014 15:24
by Traptak
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

Re: Access Violation while TOraSQL freeing

Posted: Wed 15 Jan 2014 10:46
by AlexP
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.