widestring reference counting problem when passing an OleVariant as a Variant to a procedure
Original Reporter info from Mantis: dleducq
-
Reporter name: Dominique Leducq
Original Reporter info from Mantis: dleducq
- Reporter name: Dominique Leducq
Description:
It seems that when passing an OleVariant holding a string to a procedure expecting a Variant, the reference counter of the Widestring (which stores the string internally) is not incremented correctly while passing the parameter.
In the joined test program, this causes a double memory free, which in turn causes a crash afterwards if you allocate more memory from the heap.
The compiler reserves two Variants on the stack when entering Proc2, and initializes them (fpc_initialize). They are used for parameter passing to Proc1. When copying the data into them (thus referencing the widestring), the reference counter is increased for the first, not for the second, but both are cleared by fpc_finalize when exiting Proc2, and the reference counter off the widestring is decreased twice. I did not identify the role of the second variant, nor the code where data is copied into it.... I just see with a watchpoint that this happen while calling Proc1.
Mantis conversion info:
- Mantis ID: 7095
- OS: Linux
- Fixed in version: 2.2.0
- Fixed in revision: 5131 (#5c9b3954)