Dangling pointer left behind when closing a TBufDataset
Original Reporter info from Mantis: pgimeno
-
Reporter name: Pedro Gimeno
Original Reporter info from Mantis: pgimeno
- Reporter name: Pedro Gimeno
Description:
I believe I've finally nailed the cause of #37870. It's a dangling pointer.
The patch pretty much speaks for itself, but basically: FCurrentIndexBuf was not cleared when freeing the index that it was caching, leaving it as a dangling pointer, which could cause all sorts of errors when accessing the IndexFieldNames property in particular with the dataset closed, because it uses FCurrentIndexBuf internally. This causes a random crash in Lazarus when the dataset is opened and then closed in design mode.
With the patch, some of the problems reported in 37870 with TCSVDataset and TSQLDataset are no longer reproducible, nor are other tests I made with TBufDataset.
Steps to reproduce:
I couldn't come up with a reproduction recipe, other than by using Lazarus. See #37870 for details. Hopefully the patch is sufficiently clear as to what the problem is.
But you can easily patch the same area with some code that verifies that FCurrentIndexDef equals BufIndexDefs[i] sometimes, to verify that there's indeed a problem.
Additional information:
I've tried to respect the style of the surrounding code for consistency, despite abhorring it.
Mantis conversion info:
- Mantis ID: 37932
- Build: 47066
- Version: 3.3.1
- Monitored by: » Heranuko (Heranuko)