Commit 40850267 authored by Benjamin Schaaf's avatar Benjamin Schaaf
Browse files

Fix leak in level_keyboard_new

xkb_keymap_get_as_string requires that the string it returns is freed by
the caller.
parent ec5570a5
......@@ -64,8 +64,8 @@ level_keyboard_new (struct squeek_layout *layout)
xkb_context_unref(context);
keyboard->keymap = keymap;
keymap_str = xkb_keymap_get_as_string(keymap, XKB_KEYMAP_FORMAT_TEXT_V1);
keyboard->keymap_len = strlen(keymap_str) + 1;
char * xkb_keymap_str = xkb_keymap_get_as_string(keymap, XKB_KEYMAP_FORMAT_TEXT_V1);
keyboard->keymap_len = strlen(xkb_keymap_str) + 1;
g_autofree char *path = strdup("/eek_keymap-XXXXXX");
char *r = &path[strlen(path) - 6];
......@@ -89,7 +89,8 @@ level_keyboard_new (struct squeek_layout *layout)
if ((void*)ptr == (void*)-1) {
g_error("Failed to set up mmap");
}
strncpy(ptr, keymap_str, keyboard->keymap_len);
strncpy(ptr, xkb_keymap_str, keyboard->keymap_len);
free(xkb_keymap_str);
munmap(ptr, keyboard->keymap_len);
return keyboard;
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment