libuwac/window: Fix memory leak / SIGBUS

`UwacWindowShmAllocBuffers()` allocates memory with `mmap` and never frees it
resulting in SIGBUS errors and running out of memory after some time.

Adding a corresponding `munmap` fixes this issue.
This commit is contained in:
Sascha Wessel 2020-04-26 07:53:06 +02:00 committed by akallabeth
parent 6425313776
commit a74d5b630c
2 changed files with 7 additions and 0 deletions

View File

@ -218,6 +218,7 @@ struct uwac_buffer
#endif
struct wl_buffer* wayland_buffer;
void* data;
size_t size;
};
typedef struct uwac_buffer UwacBuffer;

View File

@ -65,6 +65,7 @@ static void UwacWindowDestroyBuffers(UwacWindow* w)
region16_uninit(&buffer->damage);
#endif
wl_buffer_destroy(buffer->wayland_buffer);
munmap(buffer->data, buffer->size);
}
w->nbuffers = 0;
@ -306,11 +307,15 @@ int UwacWindowShmAllocBuffers(UwacWindow* w, int nbuffers, int allocSize, uint32
int i, fd;
void* data;
struct wl_shm_pool* pool;
size_t pagesize = sysconf(_SC_PAGESIZE);
newBuffers = xrealloc(w->buffers, (w->nbuffers + nbuffers) * sizeof(UwacBuffer));
if (!newBuffers)
return UWAC_ERROR_NOMEMORY;
/* round up to a multiple of PAGESIZE to page align data for each buffer */
allocSize = (allocSize + pagesize - 1) & ~(pagesize - 1);
w->buffers = newBuffers;
memset(w->buffers + w->nbuffers, 0, sizeof(UwacBuffer) * nbuffers);
fd = uwac_create_anonymous_file(allocSize * nbuffers);
@ -346,6 +351,7 @@ int UwacWindowShmAllocBuffers(UwacWindow* w, int nbuffers, int allocSize, uint32
region16_init(&buffer->damage);
#endif
buffer->data = data + (allocSize * i);
buffer->size = allocSize;
buffer->wayland_buffer =
wl_shm_pool_create_buffer(pool, allocSize * i, width, height, w->stride, format);
wl_buffer_add_listener(buffer->wayland_buffer, &buffer_listener, buffer);