Make sure to handle double uWS.free

This commit is contained in:
Alex Hultman 2019-12-21 19:38:02 +01:00
parent d98516e1c4
commit 6def8b2e3e
2 changed files with 20 additions and 20 deletions

View File

@ -1,3 +1,3 @@
Windows: default:
$(CC) build.c $(CC) build.c
./a.out || build.exe ./a.out || build.exe

View File

@ -47,28 +47,28 @@ bool BooleanValue(Isolate *isolate, Local<Value> value) {
/* This has to be called in beforeExit, but exit also seems okay */ /* This has to be called in beforeExit, but exit also seems okay */
void uWS_free(const FunctionCallbackInfo<Value> &args) { void uWS_free(const FunctionCallbackInfo<Value> &args) {
/* Holder is exports */
Local<Object> exports = args.Holder();
/* See if we even have free anymore */
if (exports->Get(String::NewFromUtf8(args.GetIsolate(), "free", NewStringType::kNormal).ToLocalChecked()) == Undefined(args.GetIsolate())) {
return;
}
/* Once we free uWS we remove the uWS.free function from exports */
exports->Set(args.GetIsolate()->GetCurrentContext(), String::NewFromUtf8(args.GetIsolate(), "free", NewStringType::kNormal).ToLocalChecked(), Undefined(args.GetIsolate()));
/* We get the External holding perContextData */ /* We get the External holding perContextData */
PerContextData *perContextData = (PerContextData *) Local<External>::Cast(args.Data())->Value(); PerContextData *perContextData = (PerContextData *) Local<External>::Cast(args.Data())->Value();
/* Todo: this will always be true */ /* Freeing apps here, it could be done earlier but not sooner */
if (perContextData) { perContextData->apps.clear();
/* Freeing apps here, it could be done earlier but not sooner */ perContextData->sslApps.clear();
perContextData->apps.clear(); /* Freeing the loop here means we give time for our timers to close, etc */
perContextData->sslApps.clear(); uWS::Loop::get()->free();
/* Freeing the loop here means we give time for our timers to close, etc */
uWS::Loop::get()->free();
/* We can safely delete this since we no longer can call uWS.free */
// we need to mark this delete perContextData;
delete perContextData;
// we can override the exports->free function to null after!
//args.Data()
//Local<External>::Cast(args.Data())->
}
} }
/* todo: Put this function and all inits of it in its own header */ /* todo: Put this function and all inits of it in its own header */
@ -83,7 +83,7 @@ void Main(Local<Object> exports) {
Isolate *isolate = exports->GetIsolate(); Isolate *isolate = exports->GetIsolate();
/* We want this so that we can redefine process.nextTick to using the V8 native microtask queue */ /* We want this so that we can redefine process.nextTick to using the V8 native microtask queue */
// todo: setting this might be crashing nodejs? /* Settings this crashes Node.js while debugging with breakpoints */
isolate->SetMicrotasksPolicy(MicrotasksPolicy::kAuto); isolate->SetMicrotasksPolicy(MicrotasksPolicy::kAuto);
/* Init the template objects, SSL and non-SSL, store it in per context data */ /* Init the template objects, SSL and non-SSL, store it in per context data */