From 637ecdb415e3d2f4e276e0f2d989f6bbed7a4177 Mon Sep 17 00:00:00 2001 From: Shannon Booth Date: Sun, 3 May 2020 12:21:37 +1200 Subject: [PATCH] Userland: Fix leak in keymap Pretty harmless here, but eh --- Userland/keymap.cpp | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/Userland/keymap.cpp b/Userland/keymap.cpp index 1188b62e0e..062325f6ce 100644 --- a/Userland/keymap.cpp +++ b/Userland/keymap.cpp @@ -28,21 +28,22 @@ #include #include -#include #include #include +#include #include +#include #include #include #include #include -char* read_map(const JsonObject& json, const String& name) +static Vector read_map(const JsonObject& json, const String& name) { if (!json.has(name)) - return nullptr; + return {}; - char* map = new char[0x80](); + Vector map; auto map_arr = json.get(name).as_array(); for (int i = 0; i < map_arr.size(); i++) { @@ -69,7 +70,7 @@ char* read_map(const JsonObject& json, const String& name) return map; } -RefPtr open_keymap_file(String& filename) +static RefPtr open_keymap_file(String& filename) { auto file = Core::File::construct(filename); if (file->open(Core::IODevice::ReadOnly)) @@ -89,7 +90,7 @@ RefPtr open_keymap_file(String& filename) return file; } -int read_map_from_file(String& filename) +static int read_map_from_file(String& filename) { auto file = open_keymap_file(filename); if (!file->is_open()) { @@ -100,17 +101,17 @@ int read_map_from_file(String& filename) auto file_contents = file->read_all(); auto json = JsonValue::from_string(file_contents).as_object(); - char* map = read_map(json, "map"); - char* shift_map = read_map(json, "shift_map"); - char* alt_map = read_map(json, "alt_map"); - char* altgr_map = read_map(json, "altgr_map"); + auto map = read_map(json, "map"); + auto shift_map = read_map(json, "shift_map"); + auto alt_map = read_map(json, "alt_map"); + auto altgr_map = read_map(json, "altgr_map"); - if (!altgr_map) { + if (altgr_map.is_empty()) { // AltGr map was not found, using Alt map as fallback. altgr_map = alt_map; } - Syscall::SC_setkeymap_params params { map, shift_map, alt_map, altgr_map }; + Syscall::SC_setkeymap_params params { map.data(), shift_map.data(), alt_map.data(), altgr_map.data() }; return syscall(SC_setkeymap, ¶ms); }