Thread-safety hazard in dwsUtils.AcquireUnifier function

Issue #225 resolved
Josef Kučera created an issue

Hello,
I have discovered a thread-safety problem in the AcquireUnifier function. The current implementation allows two threads to use the same TStringUnifier instance. Scenario: Thread 1 calls AcquireUnifier, reads vUnifiedStrings[0] contents and gets nil, but before really invoking InterlockedCompareExchangePointer() thread 2 releases its instance causing InterlockedCompareExchangePointer to fail (comparing vUnifiedStrings[0] to nil) but returning the real instance.
The proposed fix is to check comparand value not to be nil before invoking InterlockedCompareExchangePointer, the patch is attached.

Best regards,
Joe

Comments (2)

  1. Log in to comment