Merge pull request #74 from martinetd/more_leaks

More leaks
This commit is contained in:
Drew DeVault 2017-08-12 08:21:18 -04:00 committed by GitHub
commit 53a53f55b4
9 changed files with 55 additions and 13 deletions

View File

@ -104,6 +104,7 @@ static bool init_planes(struct wlr_backend_state *drm) {
drm->primary_planes = drm->overlay_planes + drm->num_overlay_planes; drm->primary_planes = drm->overlay_planes + drm->num_overlay_planes;
drm->cursor_planes = drm->primary_planes + drm->num_primary_planes; drm->cursor_planes = drm->primary_planes + drm->num_primary_planes;
drmModeFreePlaneResources(plane_res);
return true; return true;
error_planes: error_planes:

View File

@ -33,6 +33,7 @@ static int wlr_libinput_readable(int fd, uint32_t mask, void *_state) {
struct libinput_event *event; struct libinput_event *event;
while ((event = libinput_get_event(state->libinput))) { while ((event = libinput_get_event(state->libinput))) {
wlr_libinput_event(state, event); wlr_libinput_event(state, event);
libinput_event_destroy(event);
} }
return 0; return 0;
} }
@ -84,7 +85,9 @@ static void wlr_libinput_backend_destroy(struct wlr_backend_state *state) {
for (size_t i = 0; i < state->devices->length; i++) { for (size_t i = 0; i < state->devices->length; i++) {
list_t *wlr_devices = state->devices->items[i]; list_t *wlr_devices = state->devices->items[i];
for (size_t j = 0; j < wlr_devices->length; j++) { for (size_t j = 0; j < wlr_devices->length; j++) {
wlr_input_device_destroy(wlr_devices->items[j]); struct wlr_input_device *wlr_device = wlr_devices->items[j];
wl_signal_emit(&state->backend->events.input_remove, wlr_device);
wlr_input_device_destroy(wlr_device);
} }
list_free(wlr_devices); list_free(wlr_devices);
} }

View File

@ -111,8 +111,21 @@ static void handle_device_added(struct wlr_backend_state *state,
static void handle_device_removed(struct wlr_backend_state *state, static void handle_device_removed(struct wlr_backend_state *state,
struct libinput_device *device) { struct libinput_device *device) {
wlr_log(L_DEBUG, "libinput device removed"); list_t *devices = libinput_device_get_user_data(device);
// TODO for (size_t i = 0; i < devices->length; i++) {
struct wlr_input_device *wlr_device = devices->items[i];
wlr_log(L_DEBUG, "Removing %s [%d:%d]", wlr_device->name,
wlr_device->vendor, wlr_device->product);
wl_signal_emit(&state->backend->events.input_remove, wlr_device);
wlr_input_device_destroy(wlr_device);
}
for (size_t i = 0; i < state->devices->length; i++) {
if (state->devices->items[i] == devices) {
list_del(state->devices, i);
break;
}
}
list_free(devices);
} }
void wlr_libinput_event(struct wlr_backend_state *state, void wlr_libinput_event(struct wlr_backend_state *state,

View File

@ -85,6 +85,7 @@ static void wlr_wl_backend_destroy(struct wlr_backend_state *state) {
list_free(state->devices); list_free(state->devices);
list_free(state->outputs); list_free(state->outputs);
free(state->seatName);
wlr_egl_free(&state->egl); wlr_egl_free(&state->egl);
if (state->seat) wl_seat_destroy(state->seat); if (state->seat) wl_seat_destroy(state->seat);

View File

@ -46,6 +46,7 @@ static void wlr_wl_output_transform(struct wlr_output_state *output,
} }
static void wlr_wl_output_destroy(struct wlr_output_state *output) { static void wlr_wl_output_destroy(struct wlr_output_state *output) {
wl_signal_emit(&output->backend->backend->events.output_remove, output->wlr_output);
if(output->frame_callback) wl_callback_destroy(output->frame_callback); if(output->frame_callback) wl_callback_destroy(output->frame_callback);
eglDestroySurface(output->backend->egl.display, output->surface); eglDestroySurface(output->backend->egl.display, output->surface);
wl_egl_window_destroy(output->egl_window); wl_egl_window_destroy(output->egl_window);

View File

@ -169,6 +169,7 @@ static struct wl_keyboard_listener keyboard_listener = {
}; };
static void input_device_destroy(struct wlr_input_device_state *state) { static void input_device_destroy(struct wlr_input_device_state *state) {
wl_signal_emit(&state->backend->backend->events.input_remove, state->wlr_device);
if (state->resource) if (state->resource)
wl_proxy_destroy(state->resource); wl_proxy_destroy(state->resource);
free(state); free(state);
@ -206,7 +207,7 @@ static struct wlr_input_device *allocate_device(struct wlr_backend_state *state,
free(devstate); free(devstate);
return NULL; return NULL;
} }
devstate->wlr_device = wlr_device;
list_add(state->devices, wlr_device); list_add(state->devices, wlr_device);
return wlr_device; return wlr_device;
} }
@ -257,6 +258,7 @@ static void seat_handle_capabilities(void *data, struct wl_seat *wl_seat,
static void seat_handle_name(void *data, struct wl_seat *wl_seat, const char *name) { static void seat_handle_name(void *data, struct wl_seat *wl_seat, const char *name) {
struct wlr_backend_state *state = data; struct wlr_backend_state *state = data;
assert(state->seat == wl_seat); assert(state->seat == wl_seat);
// Do we need to check if seatName was previously set for name change?
state->seatName = strdup(name); state->seatName = strdup(name);
} }

View File

@ -311,6 +311,8 @@ static void keyboard_remove(struct wlr_input_device *device, struct compositor_s
if (!kbstate) { if (!kbstate) {
return; return;
} }
xkb_state_unref(kbstate->xkb_state);
xkb_map_unref(kbstate->keymap);
wl_list_remove(&kbstate->link); wl_list_remove(&kbstate->link);
wl_list_remove(&kbstate->key.link); wl_list_remove(&kbstate->key.link);
free(kbstate); free(kbstate);
@ -384,14 +386,13 @@ static void tablet_pad_remove(struct wlr_input_device *device, struct compositor
if (!pstate) { if (!pstate) {
return; return;
} }
// TODO probably missing more actions wl_list_remove(&pstate->button.link);
free(pstate); free(pstate);
} }
// TODO missing something that calls this on teardown
static void input_remove_notify(struct wl_listener *listener, void *data) { static void input_remove_notify(struct wl_listener *listener, void *data) {
struct wlr_input_device *device = data; struct wlr_input_device *device = data;
struct compositor_state *state = wl_container_of(listener, state, input_add); struct compositor_state *state = wl_container_of(listener, state, input_remove);
switch (device->type) { switch (device->type) {
case WLR_INPUT_DEVICE_KEYBOARD: case WLR_INPUT_DEVICE_KEYBOARD:
keyboard_remove(device, state); keyboard_remove(device, state);

View File

@ -25,7 +25,7 @@ struct wlr_backend_state {
struct wl_shell *shell; struct wl_shell *shell;
struct wl_shm *shm; struct wl_shm *shm;
struct wl_seat *seat; struct wl_seat *seat;
const char *seatName; char *seatName;
}; };
struct wlr_output_state { struct wlr_output_state {
@ -40,6 +40,7 @@ struct wlr_output_state {
struct wlr_input_device_state { struct wlr_input_device_state {
struct wlr_backend_state *backend; struct wlr_backend_state *backend;
struct wlr_input_device *wlr_device;
void *resource; void *resource;
}; };

View File

@ -30,7 +30,7 @@ static bool compile_shader(GLuint type, const GLchar *src, GLuint *shader) {
GL_CALL(glGetShaderInfoLog(*shader, loglen, &loglen, msg)); GL_CALL(glGetShaderInfoLog(*shader, loglen, &loglen, msg));
wlr_log(L_ERROR, "Shader compilation failed"); wlr_log(L_ERROR, "Shader compilation failed");
wlr_log(L_ERROR, "%s", msg); wlr_log(L_ERROR, "%s", msg);
exit(1); glDeleteShader(*shader);
return false; return false;
} }
return true; return true;
@ -43,13 +43,32 @@ static bool compile_program(const GLchar *vert_src,
return false; return false;
} }
if (!compile_shader(GL_FRAGMENT_SHADER, frag_src, &fragment)) { if (!compile_shader(GL_FRAGMENT_SHADER, frag_src, &fragment)) {
glDeleteProgram(vertex); glDeleteShader(vertex);
return false; return false;
} }
*program = GL_CALL(glCreateProgram()); *program = GL_CALL(glCreateProgram());
GL_CALL(glAttachShader(*program, vertex)); GL_CALL(glAttachShader(*program, vertex));
GL_CALL(glAttachShader(*program, fragment)); GL_CALL(glAttachShader(*program, fragment));
GL_CALL(glLinkProgram(*program)); GL_CALL(glLinkProgram(*program));
GLint success;
GL_CALL(glGetProgramiv(*program, GL_LINK_STATUS, &success));
if (success == GL_FALSE) {
GLint loglen;
GL_CALL(glGetProgramiv(*program, GL_INFO_LOG_LENGTH, &loglen));
GLchar msg[loglen];
GL_CALL(glGetProgramInfoLog(*program, loglen, &loglen, msg));
wlr_log(L_ERROR, "Program link failed");
wlr_log(L_ERROR, "%s", msg);
glDeleteProgram(*program);
glDeleteShader(vertex);
glDeleteShader(fragment);
return false;
}
glDetachShader(*program, vertex);
glDetachShader(*program, fragment);
glDeleteShader(vertex);
glDeleteShader(fragment);
return true; return true;
} }