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:
parent
6425313776
commit
a74d5b630c
@ -218,6 +218,7 @@ struct uwac_buffer
|
|||||||
#endif
|
#endif
|
||||||
struct wl_buffer* wayland_buffer;
|
struct wl_buffer* wayland_buffer;
|
||||||
void* data;
|
void* data;
|
||||||
|
size_t size;
|
||||||
};
|
};
|
||||||
typedef struct uwac_buffer UwacBuffer;
|
typedef struct uwac_buffer UwacBuffer;
|
||||||
|
|
||||||
|
@ -65,6 +65,7 @@ static void UwacWindowDestroyBuffers(UwacWindow* w)
|
|||||||
region16_uninit(&buffer->damage);
|
region16_uninit(&buffer->damage);
|
||||||
#endif
|
#endif
|
||||||
wl_buffer_destroy(buffer->wayland_buffer);
|
wl_buffer_destroy(buffer->wayland_buffer);
|
||||||
|
munmap(buffer->data, buffer->size);
|
||||||
}
|
}
|
||||||
|
|
||||||
w->nbuffers = 0;
|
w->nbuffers = 0;
|
||||||
@ -306,11 +307,15 @@ int UwacWindowShmAllocBuffers(UwacWindow* w, int nbuffers, int allocSize, uint32
|
|||||||
int i, fd;
|
int i, fd;
|
||||||
void* data;
|
void* data;
|
||||||
struct wl_shm_pool* pool;
|
struct wl_shm_pool* pool;
|
||||||
|
size_t pagesize = sysconf(_SC_PAGESIZE);
|
||||||
newBuffers = xrealloc(w->buffers, (w->nbuffers + nbuffers) * sizeof(UwacBuffer));
|
newBuffers = xrealloc(w->buffers, (w->nbuffers + nbuffers) * sizeof(UwacBuffer));
|
||||||
|
|
||||||
if (!newBuffers)
|
if (!newBuffers)
|
||||||
return UWAC_ERROR_NOMEMORY;
|
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;
|
w->buffers = newBuffers;
|
||||||
memset(w->buffers + w->nbuffers, 0, sizeof(UwacBuffer) * nbuffers);
|
memset(w->buffers + w->nbuffers, 0, sizeof(UwacBuffer) * nbuffers);
|
||||||
fd = uwac_create_anonymous_file(allocSize * 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);
|
region16_init(&buffer->damage);
|
||||||
#endif
|
#endif
|
||||||
buffer->data = data + (allocSize * i);
|
buffer->data = data + (allocSize * i);
|
||||||
|
buffer->size = allocSize;
|
||||||
buffer->wayland_buffer =
|
buffer->wayland_buffer =
|
||||||
wl_shm_pool_create_buffer(pool, allocSize * i, width, height, w->stride, format);
|
wl_shm_pool_create_buffer(pool, allocSize * i, width, height, w->stride, format);
|
||||||
wl_buffer_add_listener(buffer->wayland_buffer, &buffer_listener, buffer);
|
wl_buffer_add_listener(buffer->wayland_buffer, &buffer_listener, buffer);
|
||||||
|
Loading…
Reference in New Issue
Block a user