Skip to content
This repository
Browse code

Fix race condition in setting up RString data

We only set the type in the end if everything is ready. Before we had a
race condition where type_ was already set to cRString, but the data
wasn't allocated yet. By setting up a memory barrier and setting the
type after that, we make sure all the data is initialized properly.
  • Loading branch information...
commit 5f13e5f8d759d93500c55316da0b555d81b8a91f 1 parent d1e0eec
Dirkjan Bussink dbussink authored

Showing 1 changed file with 2 additions and 1 deletion. Show diff stats Hide diff stats

  1. +2 1  vm/capi/string.cpp
3  vm/capi/string.cpp
@@ -109,7 +109,6 @@ namespace rubinius {
109 109
110 110 unset = type_ != cRString;
111 111 if(unset) {
112   - type_ = cRString;
113 112
114 113 string->unshare(env->state());
115 114
@@ -123,6 +122,8 @@ namespace rubinius {
123 122 } else {
124 123 env->check_tracked_handle(this, false);
125 124 }
  125 + atomic::memory_barrier();
  126 + type_ = cRString;
126 127 }
127 128
128 129 env->shared().capi_ds_lock().unlock();

0 comments on commit 5f13e5f

Please sign in to comment.
Something went wrong with that request. Please try again.