From e0816b0e1049b3ac77805b7f94e010801b34e4f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ed=C3=AAnis=20Freindorfer=20Azevedo?= Date: Mon, 10 Aug 2020 15:28:04 -0300 Subject: [PATCH] Fix weird input/buttons memory leak. Deleting the vector was not enough, although it was not clear what else was causing the leak. --- src/wx/panel.cpp | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/src/wx/panel.cpp b/src/wx/panel.cpp index 5578dc575..0d7819d6e 100644 --- a/src/wx/panel.cpp +++ b/src/wx/panel.cpp @@ -1220,10 +1220,8 @@ struct game_key { wxJoyKeyBinding_v& b; }; -static std::vector* game_keys_pressed(int key, int mod, int joy) +static void game_keys_pressed(int key, int mod, int joy, std::vector* vec) { - auto vec = new std::vector; - for (int player = 0; player < 4; player++) for (int key_num = 0; key_num < NUM_KEYS; key_num++) { wxJoyKeyBinding_v& b = gopts.joykey_bindings[player][key_num]; @@ -1232,8 +1230,6 @@ static std::vector* game_keys_pressed(int key, int mod, int joy) if (b[bind_num].key == key && b[bind_num].mod == mod && b[bind_num].joy == joy) vec->push_back({player, key_num, (int)bind_num, b}); } - - return vec; } static bool process_key_press(bool down, int key, int mod, int joy = 0) @@ -1267,9 +1263,10 @@ static bool process_key_press(bool down, int key, int mod, int joy = 0) if (keys_pressed[kpno].key == key && keys_pressed[kpno].mod == mod && keys_pressed[kpno].joy == joy) break; - auto game_keys = game_keys_pressed(key, mod, joy); + std::vector game_keys; + game_keys_pressed(key, mod, joy, &game_keys); - const bool is_game_key = game_keys->size(); + const bool is_game_key = game_keys.size(); if (kpno < keys_pressed.size()) { // double press is noop @@ -1287,7 +1284,7 @@ static bool process_key_press(bool down, int key, int mod, int joy = 0) keys_pressed.push_back({key, mod, joy}); } - for (auto&& game_key : *game_keys) { + for (auto&& game_key : game_keys) { if (down) { // press button joypress[game_key.player] |= bmask[game_key.key_num]; @@ -1313,8 +1310,6 @@ static bool process_key_press(bool down, int key, int mod, int joy = 0) } } - delete game_keys; - return is_game_key; }