Skip to content

Commit

Permalink
Fixed webp native memory leak
Browse files Browse the repository at this point in the history
Summary:
Fixed bug facebook#2073

it is a obvious bug, and i found the native memory do not increase when i use this patch

Sign the [CLA][2], if you haven't already.

Small pull requests are much easier to review and more likely to get merged. Make sure the PR does only one thing, otherwise please split it.

Make sure all **tests pass** on [Circle CI][4]. PRs that break tests are unlikely to be merged.

For more info, see the [Contributing guide][4].

[1]: https://medium.com/martinkonicek/what-is-a-test-plan-8bfc840ec171#.y9lcuqqi9
[2]: https://code.facebook.com/cla
[3]: http://circleci.com/gh/facebook/fresco
[4]: https://github.com/facebook/fresco/blob/master/CONTRIBUTING.md
Closes facebook#2079

Reviewed By: cuva

Differential Revision: D7398009

Pulled By: lambdapioneer

fbshipit-source-id: 927f079bd0f80fa8f8f19592a5e49207d266f34e
  • Loading branch information
Howard@win authored and facebook-github-bot committed Mar 27, 2018
1 parent 8997d4e commit 7bb10e0
Showing 1 changed file with 15 additions and 16 deletions.
31 changes: 15 additions & 16 deletions static-webp/src/main/jni/static-webp/webp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -438,37 +438,36 @@ jobject WebPImage_nativeGetFrame(JNIEnv* pEnv, jobject thiz, jint index) {
return nullptr;
}


auto spIter = std::unique_ptr<WebPIterator, decltype(&WebPDemuxReleaseIterator)> {
new WebPIterator(),
WebPDemuxReleaseIterator
};
WebPIterator iter= {0};

// Note, in WebP, frame numbers are one-based.
if (!WebPDemuxGetFrame(spNativeContext->spDemuxer->get(), index + 1, spIter.get())) {
if (!WebPDemuxGetFrame(spNativeContext->spDemuxer->get(), index + 1, &iter)) {
throwIllegalStateException(pEnv, "unable to get frame");
WebPDemuxReleaseIterator(&iter);
return nullptr;
}

std::unique_ptr<WebPFrameNativeContext> spFrameNativeContext(new WebPFrameNativeContext());
if (!spFrameNativeContext) {
throwOutOfMemoryError(pEnv, "Unable to allocate WebPFrameNativeContext");
WebPDemuxReleaseIterator(&iter);
return nullptr;
}

spFrameNativeContext->spDemuxer = spNativeContext->spDemuxer;
spFrameNativeContext->frameNum = spIter->frame_num;
spFrameNativeContext->xOffset = spIter->x_offset;
spFrameNativeContext->yOffset = spIter->y_offset;
spFrameNativeContext->durationMs = spIter->duration;
spFrameNativeContext->width = spIter->width;
spFrameNativeContext->height = spIter->height;
spFrameNativeContext->frameNum = iter.frame_num;
spFrameNativeContext->xOffset = iter.x_offset;
spFrameNativeContext->yOffset = iter.y_offset;
spFrameNativeContext->durationMs = iter.duration;
spFrameNativeContext->width = iter.width;
spFrameNativeContext->height = iter.height;
spFrameNativeContext->disposeToBackgroundColor =
spIter->dispose_method == WEBP_MUX_DISPOSE_BACKGROUND;
spFrameNativeContext->blendWithPreviousFrame = spIter->blend_method == WEBP_MUX_BLEND;
spFrameNativeContext->pPayload = spIter->fragment.bytes;
spFrameNativeContext->payloadSize = spIter->fragment.size;
iter.dispose_method == WEBP_MUX_DISPOSE_BACKGROUND;
spFrameNativeContext->blendWithPreviousFrame = iter.blend_method == WEBP_MUX_BLEND;
spFrameNativeContext->pPayload = iter.fragment.bytes;
spFrameNativeContext->payloadSize = iter.fragment.size;

WebPDemuxReleaseIterator(&iter);
jobject ret = pEnv->NewObject(
sClazzWebPFrame,
sWebPFrameConstructor,
Expand Down

0 comments on commit 7bb10e0

Please sign in to comment.