Thread-safety hazard in dwsUtils.TidyStringsUnifier

Issue #233 resolved
Josef Kučera created an issue

Hello,
I have discovered a thread-safety problem (similar to issue #225) in the TidyStringsUnifier function. The current implementation allows to clean TStringUnifier instance still present in vUnifiedStrings[]. Scenario: Thread 1 calls TidyStringsUnifier, reads vUnifiedStrings[n] contents and gets nil, but before really invoking InterlockedCompareExchangePointer() thread 2 releases its instance causing InterlockedCompareExchangePointer to fail (comparing vUnifiedStrings[n] 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 (1)

  1. Log in to comment