Skip to content

Commit dd2d883

Browse files
committed
Fix a couple of potential memory leaks discovered via LSAN
1 parent 1189cf4 commit dd2d883

2 files changed

Lines changed: 15 additions & 9 deletions

File tree

‎docs/src/content/docs/changelog/v0.35.6.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ slug: changelog/v0.35.6
77
https://github.com/lovell/sharp-libvips/releases/tag/v1.3.4
88
:::
99

10+
* Fix potential memory leak when requesting transferable `ArrayBuffer` via `toUint8Array`.
11+
12+
* Fix potential memory leak when extending animated images.
13+
1014
* Prevent possible corruption when retaining ICC profile.
1115
[#4615](https://github.com/lovell/sharp/pull/4615)
1216
[@metsw24-max](https://github.com/metsw24-max)

‎src/pipeline.cc‎

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -638,15 +638,17 @@ class PipelineWorker : public Napi::AsyncWorker {
638638
std::tie(image, background) = sharp::ApplyAlpha(image, baton->extendBackground, shouldPremultiplyAlpha);
639639
}
640640
image = sharp::StaySequential(image, nPages > 1 || baton->extendWith != VIPS_EXTEND_BACKGROUND);
641-
auto options = VImage::option()->set("extend", baton->extendWith);
642-
if (baton->extendWith == VIPS_EXTEND_BACKGROUND) {
643-
options->set("background", background);
641+
if (nPages > 1) {
642+
image = sharp::EmbedMultiPage(image,
643+
baton->extendLeft, baton->extendTop, baton->width, baton->height,
644+
baton->extendWith, background, nPages, &targetPageHeight);
645+
} else {
646+
auto options = VImage::option()->set("extend", baton->extendWith);
647+
if (baton->extendWith == VIPS_EXTEND_BACKGROUND) {
648+
options->set("background", background);
649+
}
650+
image = image.embed(baton->extendLeft, baton->extendTop, baton->width, baton->height, options);
644651
}
645-
image = nPages > 1
646-
? sharp::EmbedMultiPage(image,
647-
baton->extendLeft, baton->extendTop, baton->width, baton->height,
648-
baton->extendWith, background, nPages, &targetPageHeight)
649-
: image.embed(baton->extendLeft, baton->extendTop, baton->width, baton->height, options);
650652
if (baton->keepGainMap) {
651653
gainMap = gainMap.embed(baton->extendLeft / gainMapScaleFactor, baton->extendTop / gainMapScaleFactor,
652654
baton->width / gainMapScaleFactor, baton->height / gainMapScaleFactor, VImage::option()
@@ -1468,7 +1470,7 @@ class PipelineWorker : public Napi::AsyncWorker {
14681470
// ECMAScript ArrayBuffer with Uint8Array view
14691471
Napi::TypedArrayOf<uint8_t> data = Napi::Buffer<char>::Copy(env,
14701472
static_cast<char*>(baton->bufferOut), baton->bufferOutLength);
1471-
sharp::FreeCallback(static_cast<char*>(baton->bufferOut), nullptr);
1473+
sharp::FreeCallback(nullptr, static_cast<char*>(baton->bufferOut));
14721474
Callback().SHARP_CALLBACK_FN_NAME(Receiver().Value(), { env.Null(), data, info });
14731475
} else {
14741476
// Node.js Buffer

0 commit comments

Comments
 (0)