@@ -134,6 +134,10 @@ class Disruptor : public Napi::ObjectWrap<Disruptor>
134
134
Napi::Value GetPendingSeqNext (const Napi::CallbackInfo& info);
135
135
Napi::Value GetPendingSeqNextEnd (const Napi::CallbackInfo& info);
136
136
Napi::Value GetElementSize (const Napi::CallbackInfo& info);
137
+
138
+ void ThrowErrnoError (const Napi::CallbackInfo& info,
139
+ const char *msg,
140
+ bool constructing = false );
137
141
};
138
142
139
143
void NullCallback (const Napi::CallbackInfo& info)
@@ -352,8 +356,22 @@ class CloseFD
352
356
}
353
357
};
354
358
355
- void ThrowErrnoError (const Napi::CallbackInfo& info, const char *msg)
359
+ void Disruptor::ThrowErrnoError (const Napi::CallbackInfo& info,
360
+ const char *msg,
361
+ bool constructing)
356
362
{
363
+ // Work around bug in ObjectWrap destruction
364
+ // https://github.com/nodejs/node-addon-api/pull/475
365
+ // Remove this code and 'constructing' parameter when the PR is merged
366
+ if (constructing && !IsEmpty ())
367
+ {
368
+ Napi::Object object = Value ();
369
+ if (!object.IsEmpty ())
370
+ {
371
+ napi_remove_wrap (Env (), object, nullptr );
372
+ }
373
+ }
374
+
357
375
int errnum = errno;
358
376
char buf[1024 ] = {0 };
359
377
auto errmsg = strerror_r (errnum, buf, sizeof (buf));
@@ -383,7 +401,7 @@ Disruptor::Disruptor(const Napi::CallbackInfo& info) :
383
401
S_IRUSR | S_IWUSR)));
384
402
if (*shm_fd < 0 )
385
403
{
386
- ThrowErrnoError (info, " Failed to open shared memory object" );
404
+ ThrowErrnoError (info, " Failed to open shared memory object" , true );
387
405
}
388
406
389
407
// Allow space for all the elements,
@@ -397,7 +415,7 @@ Disruptor::Disruptor(const Napi::CallbackInfo& info) :
397
415
// Note: ftruncate initializes to null bytes.
398
416
if (init && (ftruncate (*shm_fd, shm_size) < 0 ))
399
417
{
400
- ThrowErrnoError (info, " Failed to size shared memory" ); // LCOV_EXCL_LINE
418
+ ThrowErrnoError (info, " Failed to size shared memory" , true ); // LCOV_EXCL_LINE
401
419
}
402
420
403
421
// Map the shared memory
@@ -408,7 +426,7 @@ Disruptor::Disruptor(const Napi::CallbackInfo& info) :
408
426
0 );
409
427
if (shm_buf == MAP_FAILED)
410
428
{
411
- ThrowErrnoError (info, " Failed to map shared memory" ); // LCOV_EXCL_LINE
429
+ ThrowErrnoError (info, " Failed to map shared memory" , true ); // LCOV_EXCL_LINE
412
430
413
431
}
414
432
0 commit comments