Permalink
Browse files

Don't segfault while calling yield with no fiber

require('fibers');
yield();

Dereferencing uninitialized pointers is generally bad.
  • Loading branch information...
1 parent a203d61 commit f8631b294086918ac1acdb8785012cb002c9a24d @laverdet committed Jan 24, 2011
Showing with 6 additions and 0 deletions.
  1. +6 −0 src/fibers.cc
View
@@ -387,6 +387,11 @@ class Fiber {
*/
static Handle<Value> Yield(const Arguments& args) {
HandleScope scope;
+
+ if (current == NULL) {
+ THROW(Exception::Error, "yield() called with no fiber running");
+ }
+
Fiber& that = *current;
if (that.zombie) {
@@ -448,6 +453,7 @@ class Fiber {
// application is going down lost memory isn't the end of the world. But with a regular lock
// there's seg faults when node shuts down.
Fiber::locker = new Locker;
+ current = NULL;
HandleScope scope;
tmpl = Persistent<FunctionTemplate>::New(FunctionTemplate::New(New));
tmpl->SetClassName(String::NewSymbol("Fiber"));

0 comments on commit f8631b2

Please sign in to comment.