Skip to content

Commit

Permalink
REGRESSION(b51f539): Fix memory leak when the buffer is destroyed at …
Browse files Browse the repository at this point in the history
…view-backend-exportable-fdo-egl

Since commit b51f539 there is a memory leak each time the wl_resource is destroyed.
This can be easily reproduced by repeteadly switching full-screen on/off
(pressing F11 key) with Cog on Weston.

The memory leak is caused because since b51f539 the wpe_fdo_egl_exported_image object
is not cleaned anymore on the bufferDestroyListenerCallback callback.

Commit cb6b86a fixed the leak but introduced crashes on some cases, so it was reverted.

This is a new attempt at fixing this leak, this adds safeguards to ensure that the
image object is not cleaned twice or with the wrong exported status.

Related-to: #73 #175 #176 #178
Related-to: Igalia/cog#538
  • Loading branch information
clopez committed Sep 11, 2024
1 parent 330f277 commit 5b1c5e4
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions src/view-backend-exportable-fdo-egl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -247,9 +247,13 @@ class ClientBundleEGL final : public ClientBundle {

void releaseImage(struct wpe_fdo_egl_exported_image* image)
{
if (image->bufferResource)
viewBackend->releaseBuffer(image->bufferResource);
else
if (!image)
return;
if (image->exported) {
image->exported = false;
if (image->bufferResource)
viewBackend->releaseBuffer(image->bufferResource);
} else
deleteImage(image);
}

Expand Down Expand Up @@ -285,16 +289,20 @@ class ClientBundleEGL final : public ClientBundle {
{
assert(image->eglImage);
WS::instanceImpl<WS::ImplEGL>().destroyImage(image->eglImage);

delete image;
}

static void bufferDestroyListenerCallback(struct wl_listener* listener, void*)
{
struct wpe_fdo_egl_exported_image* image;
image = wl_container_of(listener, image, bufferDestroyListener);

image->bufferResource = nullptr;
// The image object is inmediately destroyed here only if it's not currently
// exported, otherwise it's destroyed when the client releases/returns it.
if (image->exported) {
image->exported = false;
image->bufferResource = nullptr;
} else
deleteImage(image);
}
};

Expand Down

0 comments on commit 5b1c5e4

Please sign in to comment.