Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Guard usage of RData for already freed Data objects

When a Data object is already freed, we can't use the raw pointer
anymore that it used to point to some C allocated data. When this
happens we raise an exception so code after for example a call to
DATA_PTR, can't run and cause segfaults.
  • Loading branch information...
commit fad3d9d0c99c042821b1bb398d02a0f5255a5394 1 parent c733100
@dbussink dbussink authored
View
1  vm/builtin/nativemethod.cpp
@@ -74,7 +74,6 @@ namespace rubinius {
handle->update(NativeMethodEnvironment::get());
}
} else {
- assert(!try_as<Data>(obj));
handle = state->shared().add_global_handle(state, obj);
handles_.add_if_absent(handle);
}
View
26 vm/capi/data.cpp
@@ -11,17 +11,27 @@ using namespace rubinius::capi;
namespace rubinius {
namespace capi {
- RData* Handle::create_rdata(NativeMethodEnvironment* env) {
- type_ = cRData;
+ RData* Handle::as_rdata(NativeMethodEnvironment* env) {
+ Data* data = as<Data>(object_);
- RData* rdata = new RData;
- rdata->data = 0;
- rdata->dmark = 0;
- rdata->dfree = 0;
+ if(data->freed_p()) {
+ rb_raise(rb_eArgError, "Data object has already been freed");
+ }
- as_.rdata = rdata;
+ if(type_ == cRData) {
+ return as_.rdata;
+ } else {
+ type_ = cRData;
- return rdata;
+ RData* rdata = new RData;
+ rdata->data = 0;
+ rdata->dmark = 0;
+ rdata->dfree = 0;
+
+ as_.rdata = rdata;
+
+ return rdata;
+ }
}
}
}
View
10 vm/capi/handle.hpp
@@ -190,15 +190,7 @@ namespace rubinius {
as_.next_index_ = next_index;
}
- RData* create_rdata(NativeMethodEnvironment* env);
- RData* as_rdata(NativeMethodEnvironment* env) {
- if(type_ == cRData) {
- return as_.rdata;
- } else {
- return create_rdata(env);
- }
- }
-
+ RData* as_rdata(NativeMethodEnvironment* env);
RArray* as_rarray(NativeMethodEnvironment* env);
RString* as_rstring(NativeMethodEnvironment* env, int cache_level);
RFloat* as_rfloat(NativeMethodEnvironment* env);
Please sign in to comment.
Something went wrong with that request. Please try again.