Memory Leak in DataSet Parameter Binding
Original Reporter info from Mantis: aurawin
-
Reporter name: Andrew Brunner
Original Reporter info from Mantis: aurawin
- Reporter name: Andrew Brunner
Description:
TParam.SetAsFloat method causes read access violation...
./rtl/inc/variants.pp
procedure DoVarCopy(var Dest : TVarData; const Source : TVarData);
begin
if @Dest <> @Source then
if (Source.vType and varComplexType) = 0 then begin
DoVarClearIfComplex(Dest);
Dest := Source;
end else
DoVarCopyComplex(Dest, Source);
end;
in ./rtl/inc/variant.inc
procedure fpc_variant_copy(var d: tvardata; const s : tvardata);[Public,Alias:'FPC_VARIANT_COPY']; compilerproc;
begin
if assigned(VarCopyProc) then
VarCopyProc(d,s);
end;
VarCopyProc(d,s) is called with a "d" that is not initialized. When d is not initialized properly the variant can be string and the string field is filled with junk.
Further, because the Type of the Parameter is not pre-set there are multiple access to rtl method fpc_variant_copy method.
Steps to reproduce:
All of my applications that employ fields with strings & floats have this problem and no longer function properly.
Additional information:
This is a new problem for me. I don't know what changed with variable initialization but a quick fix is below...
Procedure TParam.SetAsFloat(const AValue: Double);
begin
FDataType:=ftFloat;
Value:=AValue;
end;
By pre-setting the type of data before assigning the value, the value is set and the code runs more efficient and the flaw is no longer exposed (because the reduction in calls to fpc_variant_copy
Mantis conversion info:
- Mantis ID: 24728
- OS: Ubuntu x64
- OS Build: 13.04
- Build: 25053
- Platform: AMD 8 Core x64 Linux
- Fixed in version: 2.6.4
- Fixed in revision: 25468 (#4346cb1b)
- Monitored by: » BigChimp (Reinier Olislagers), » luizamerico (Luiz Americo)
- Target version: 2.6.3