TBufdataset with persistent field crashes when it is closed

Summary

TBufDataset crashes when persistent fields have been added at designtime and the Active property is switched to false.

System Information

  • Operating system: tested on Windows 11
  • Processor architecture: tested on x86-64
  • Compiler version: Lazarus 2.3.0 (rev main-2_3-1020-gc87b73cadc) FPC 3.3.1 i386-win32-win32/win64 (FPC commit a9c67f22)
  • Device: Desktop PC

Steps to reproduce

  • The attached demo project contains a TBufDataset with one persistent field. The lfm file has been stored in state ``Active=true''.
  • Compile and run the project.
  • Click on the left button "Add value". -> Some dummy text is added to the dataset, it appears in the left DBGrid.
  • Click on the left button "Close". It is supposed to close the dataset. --> the application crashes with the message "Project project1 raised exception class 'External: SIGSEGV'. In file '..\inc\heap.inc' at line 1127".

For comparison that this only happens with persistent fields repeat the same in the right-hand part of the form:

  • Click on the right button "Create field" to create a field at runtime for another dataset.
  • Click on the right button "Add value"
  • Click on the right button "Close" --> no crash.

Example Project

See attachment: 39635_-_bufdataset_crashing_when_closing_dataset.zip

Based on the sample project of issue freepascal.org/lazarus/lazarus#39635 which probably is caused by the same bug.

What is the current bug behavior?

Crash

What is the expected (correct) behavior?

No crash

Possible fixes

No fix at the moment, but the crash occurs in TDataset.SetBufListSize called from TDataset.CloseCursor.

Edited by Werner Pamler