From a92054a04037a306b95de7b2cec747ae35080f7b Mon Sep 17 00:00:00 2001 From: wp Date: Tue, 2 Apr 2019 20:24:36 +0000 Subject: [PATCH] TAChart: Add try-finally block to TCubicSplineSeries.PrepareCoeffs. Issue #35268, patch by Marcin Wiazowski git-svn-id: trunk@60821 - --- components/tachart/tafuncseries.pas | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/components/tachart/tafuncseries.pas b/components/tachart/tafuncseries.pas index d98922cf78..83f3eb7991 100644 --- a/components/tachart/tafuncseries.pas +++ b/components/tachart/tafuncseries.pas @@ -1541,22 +1541,31 @@ procedure TCubicSplineSeries.PrepareCoeffs; var i: Integer = 0; j: Integer = 0; + sCount: Integer = 0; s: TSpline; begin FreeSplines; SetLength(FX, Source.Count); SetLength(FY, Source.Count); - while i < Source.Count do begin - s := TSpline.Create(self); - if s.PrepareCoeffs(Source, i, j) then begin - SetLength(FSplines, Length(FSplines) + 1); - FSplines[High(FSplines)] := s; - end - else - s.Free; + SetLength(FSplines, Source.Count); + try + while i < Source.Count do begin + s := TSpline.Create(self); + try + if s.PrepareCoeffs(Source, i, j) then begin + FSplines[sCount] := s; + s := nil; + sCount += 1; + end; + finally + s.Free; + end; + end; + SetLength(FX, j); + SetLength(FY, j); + finally + SetLength(FSplines, sCount); end; - SetLength(FX, j); - SetLength(FY, j); end; procedure TCubicSplineSeries.SetBadDataPen(AValue: TBadDataChartPen);