Skip to content

Commit 494035d

Browse files
committed
leak in sync toBuffer
Claude found it right away Fixes #2490
1 parent 367af8c commit 494035d

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/Canvas.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,6 @@ static void setPdfMetadata(Canvas* canvas, Napi::Object opts) {
368368

369369
Napi::Value
370370
Canvas::ToBuffer(const Napi::CallbackInfo& info) {
371-
EncodingWorker *worker = new EncodingWorker(info.Env());
372371
cairo_status_t status;
373372

374373
// Vector canvases, sync only
@@ -434,7 +433,6 @@ Canvas::ToBuffer(const Napi::CallbackInfo& info) {
434433
CairoError(ex).ThrowAsJavaScriptException();
435434
} catch (const char* ex) {
436435
Napi::Error::New(env, ex).ThrowAsJavaScriptException();
437-
438436
}
439437

440438
return env.Undefined();
@@ -461,6 +459,7 @@ Canvas::ToBuffer(const Napi::CallbackInfo& info) {
461459

462460
// Make sure the surface exists since we won't have an isolate context in the async block:
463461
surface();
462+
EncodingWorker* worker = new EncodingWorker(env);
464463
worker->Init(&ToPngBufferAsync, closure);
465464
worker->Queue();
466465

@@ -498,6 +497,7 @@ Canvas::ToBuffer(const Napi::CallbackInfo& info) {
498497

499498
// Make sure the surface exists since we won't have an isolate context in the async block:
500499
surface();
500+
EncodingWorker* worker = new EncodingWorker(env);
501501
worker->Init(&ToJpegBufferAsync, closure);
502502
worker->Queue();
503503
return env.Undefined();

0 commit comments

Comments
 (0)