Subject | FOutDa memory leak when Prepare fails |
---|---|
Author | |
Post date | 2017-03-22T11:30:38Z |
I have a construct like this:
DataModule := GetFromPool;
try
DataSet := DataModule.GetDS;
try
DataSet.Prepare;
DataSet.Params[0].AsString := 'some value';
DataSet.Open;
DoWork(DataSet);
DataSet.IB_Transaction.Commit;
except
DataSet.IB_Transaction.Rollback;
raise;
end;
finally
ReleaseToPool(DataModule);
end;
I don't know why the following happens to me only now and not before but:
If i "blotch" the SQL property (DataSet is a TIB_Cursor) i'll get an exception raised from within DataSet.Prepare. I can catch and handle this properly logging even the "ServerSQL". So very good.
However, when the exception occurs before the prepare is finished the FOutDa member of the TIB_Cursor never gets freed. Even if i put a call to DataSet.Unprepare before or after the rollback because the internal prepared flag never gets set so the unprepare is just skipped.
IMHO a check if FOutDa and FInDa would be a boon. I do not know if it should be done as a response to a connection event or in the destructor. I guess it would work to just FreeAndNilMem in the destructor because the other two places uses FreeAndNilMem. At least, putting:
FreeAndNilMem( FInDa );
FreeAndNilMem( FOutDa );
Regards,
/Dany