Calling Persistent<Function> callback segfaults in AfterWork

The below code works in OS X, but when I compile & run it in Ubuntu, I get a segfault when calling the baton->callback function. It seems that the Persistent<Function> doesn't persist past the initial Aysnc::Start method.

If this is the case, why does it work on OS X? What can I do to make it work cross-platform?

If I'm doing it wrong, what do I need to do in order to make my callback callable from AfterWork?

// Async.h

#include <v8.h>
#include <node.h>
#include <string>

using namespace node;
using namespace v8;

class Async : public ObjectWrap {
  public:
    static Persistent<Function> constructor_template;
    static void Initialize(Handle<v8::Object> target);

  protected:
    Async() {}
    ~Async() {}

    static Handle<Value> Start(const Arguments& args);
    static void Work(uv_work_t* req);
    static void AfterWork(uv_work_t* req);
  private:

    struct Baton {
      uv_work_t request;
      Persistent<Function> callback;
    };
};

// Async.cc
Handle<Value> Async::Start(const Arguments& args) {
  HandleScope scope;

  if(args.Length() == 0 || !args[0]->IsFunction()) {
    return ThrowException(Exception::Error(String::New("Callback is required and must be a Function.")));
  }

  Baton *baton = new Baton();
  baton->request.data = baton;
  baton->callback = Persistent<Function>::New(Handle<Function>::Cast(args[0]));

  uv_queue_work(uv_default_loop(), &baton->request, Work, (uv_after_work_cb)AfterWork);

  return Undefined();
}

void Async::Work(uv_work_t *req) {
  printf("Work\n");
}

void Async::AfterWork(uv_work_t *req) {
  printf("AfterWork\n");
  HandleScope scope;

  Baton *baton = static_cast<Baton *>(req->data);
  delete req;

    Local<Value> argv[1] = {
      Local<Value>::New(Null());
    };

    TryCatch try_catch;
    // Segfault occurs here
    baton->callback->Call(Context::GetCurrent()->Global(), 1, argv);
    if (try_catch.HasCaught()) {
      node::FatalException(try_catch);
    }
}

I'm not familiar with libuv, but given your definition of Baton, and assuming that the uv_work_t* passed into AfterWork() is the same as the one passed into uv_queue_work(), your delete req statement actually deletes your Baton structure, from which you then attempt to read the callback field. I'd try removing delete req and adding delete baton at the very end of AfterWork().