From 7a4eaeaa8e5ac16311ad051af046d82901d0c86e Mon Sep 17 00:00:00 2001 From: DreamMaoMao <2523610504@qq.com> Date: Wed, 27 Aug 2025 10:23:33 +0800 Subject: [PATCH] fix: miss free kb_layout memory --- src/dispatch/bind_define.h | 5 +---- src/fetch/common.h | 4 ++-- src/mango.c | 7 ++----- 3 files changed, 5 insertions(+), 11 deletions(-) diff --git a/src/dispatch/bind_define.h b/src/dispatch/bind_define.h index 72ab8fa..f39543f 100644 --- a/src/dispatch/bind_define.h +++ b/src/dispatch/bind_define.h @@ -671,7 +671,7 @@ void switch_keyboard_layout(const Arg *arg) { } // 3. 分配并获取布局缩写 - char **layout_ids = calloc(num_layouts, sizeof(char *)); + const char **layout_ids = calloc(num_layouts, sizeof(char *)); if (!layout_ids) { wlr_log(WLR_ERROR, "Failed to allocate layout IDs"); goto cleanup_context; @@ -743,9 +743,6 @@ void switch_keyboard_layout(const Arg *arg) { xkb_keymap_unref(new_keymap); cleanup_layouts: - for (int i = 0; i < num_layouts; i++) { - free(layout_ids[i]); - } free(layout_ids); cleanup_context: diff --git a/src/fetch/common.h b/src/fetch/common.h index 6f7b076..d913d60 100644 --- a/src/fetch/common.h +++ b/src/fetch/common.h @@ -44,11 +44,11 @@ char *get_autostart_path(char *autostart_path, unsigned int buf_size) { return autostart_path; } -char *get_layout_abbr(const char *full_name) { +const char *get_layout_abbr(const char *full_name) { // 1. 尝试在映射表中查找 for (int i = 0; layout_mappings[i].full_name != NULL; i++) { if (strcmp(full_name, layout_mappings[i].full_name) == 0) { - return strdup(layout_mappings[i].abbr); + return layout_mappings[i].abbr; } } diff --git a/src/mango.c b/src/mango.c index 0607c07..d6c277c 100644 --- a/src/mango.c +++ b/src/mango.c @@ -666,7 +666,7 @@ wlr_scene_tree_snapshot(struct wlr_scene_node *node, struct wlr_scene_tree *parent); static bool is_scroller_layout(Monitor *m); void create_output(struct wlr_backend *backend, void *data); -char *get_layout_abbr(const char *full_name); +static const char *get_layout_abbr(const char *full_name); void apply_named_scratchpad(Client *target_client); Client *get_client_by_id_or_title(const char *arg_id, const char *arg_title); bool switch_scratchpad_client_state(Client *c); @@ -4269,7 +4269,7 @@ void reset_keyboard_layout(void) { } // Get layout abbreviations - char **layout_ids = calloc(num_layouts, sizeof(char *)); + const char **layout_ids = calloc(num_layouts, sizeof(char *)); if (!layout_ids) { wlr_log(WLR_ERROR, "Failed to allocate layout IDs"); goto cleanup_context; @@ -4314,9 +4314,6 @@ void reset_keyboard_layout(void) { xkb_keymap_unref(new_keymap); cleanup_layouts: - for (int i = 0; i < num_layouts; i++) { - free(layout_ids[i]); - } free(layout_ids); cleanup_context: