#1 2016-09-01 09:16:17

mingda
Member
Registered: 2013-01-04
Posts: 121

sometime AV occur at TDynArrayHashed.HashAdd

in TDynArrayHashed.HashAdd sometimes fHashsCount = 256, but Length(fHashs)=0,

  with fHashs[-result-1] do begin // HashFind returned negative index in fHashs[]
    Hash := aHashCode;
    Index := n;
  end;

this cause write fHashs[-result-1] will generate AV(here result=-1),

but not every time this occure, i have a function like this:

function test(const aParam: RawUTF8; aConnection: TSQLDBConnection): Boolean;
var
  sql: RawUTF8;
  rows, updateStatement: ISQLDBStatement;
begin
  rows := aConnection.NewStatementPrepared(sql, true);
  if not Assigned(rows) then exit;
  rows.Bind([aParam]);
  rows.ExecutePrepared;
....
end;

below is log, thanks

20160901 07132747 EXCOS EAccessViolation (C0000005) at 00516473 SynCommons.TDynArrayHashed.HashAdd (42926)  stack trace API 0051662B SynCommons.TDynArrayHashed.FindHashedForAdding (42960) 00516689 SynCommons.TDynArrayHashed.AddAndMakeUniqueName (42971) 0055C758 SynOleDB.TOleDBStatement.BindColumns (2215) 0055BDBD SynOleDB.TOleDBStatement.FromRowSet (2024) 0055B89B SynOleDB.TOleDBStatement.ExecutePrepared (1989) 006BF93F 

Offline

#2 2016-09-01 14:14:06

mingda
Member
Registered: 2013-01-04
Posts: 121

Re: sometime AV occur at TDynArrayHashed.HashAdd

when reuse a cache statement

procedure TOleDBStatement.Reset;
begin
...
    fColumn.Clear;
    fColumn.ReHash;
...
end;

seems TDynArrayHashed.ReHash need add fHashsCount := 0

function TDynArrayHashed.ReHash(aHasher: TOnDynArrayHashOne=nil): boolean;
var i, n, cap, ndx: integer;
    P: PAnsiChar;
    aHashCode: cardinal;
begin
  result := false;
  fHashs := nil;
  fHashsCount := 0;    //add this to reset count
  n := Count;
  if (n=0) or (n<fHashCountTrigger) then
    exit; // hash only if needed, and avoid GPF after TDynArray.Clear (Count=0)

Offline

#3 2016-09-01 16:27:13

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,661
Website

Re: sometime AV occur at TDynArrayHashed.HashAdd

Please check http://synopse.info/fossil/info/ddc1dc391a

Thanks for the feedback!

Offline

Board footer

Powered by FluxBB