mirror of
https://github.com/hyprwm/wlroots-hyprland.git
synced 2024-11-22 12:55:58 +01:00
Prevent memory leak in copypaste of the screencopy example
If someone want to use screencopy as is processing multiple screenshots - it could be hard to find this issue with shm.
This commit is contained in:
parent
30308e35fa
commit
13db99b0f8
1 changed files with 5 additions and 0 deletions
|
@ -35,6 +35,7 @@
|
|||
#include <sys/stat.h>
|
||||
#include <sys/wait.h>
|
||||
#include <unistd.h>
|
||||
#include <assert.h>
|
||||
#include <wayland-client-protocol.h>
|
||||
#include "wlr-screencopy-unstable-v1-client-protocol.h"
|
||||
|
||||
|
@ -111,6 +112,9 @@ static void frame_handle_buffer(void *data,
|
|||
buffer.width = width;
|
||||
buffer.height = height;
|
||||
buffer.stride = stride;
|
||||
|
||||
// Make sure the buffer is not allocated
|
||||
assert(!buffer.wl_buffer);
|
||||
buffer.wl_buffer =
|
||||
create_shm_buffer(format, width, height, stride, &buffer.data);
|
||||
if (buffer.wl_buffer == NULL) {
|
||||
|
@ -257,6 +261,7 @@ int main(int argc, char *argv[]) {
|
|||
write_image("wayland-screenshot.png", buffer.format, buffer.width,
|
||||
buffer.height, buffer.stride, buffer.y_invert, buffer.data);
|
||||
wl_buffer_destroy(buffer.wl_buffer);
|
||||
munmap(buffer.data, buffer.stride * buffer.height);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue