diff --git a/src/bnusio.cpp b/src/bnusio.cpp index 268ea55..bd3b383 100644 --- a/src/bnusio.cpp +++ b/src/bnusio.cpp @@ -321,8 +321,9 @@ Init () { INSTALL_HOOK (bngrw_attach); INSTALL_HOOK (bngrw_reqWaitTouch); - auto configPath = std::filesystem::current_path () / "config.toml"; - toml_table_t *config = openConfig (configPath); + auto configPath = std::filesystem::current_path () / "config.toml"; + std::unique_ptr config_ptr (openConfig (configPath), toml_free); + toml_table_t *config = config_ptr.get (); if (config) { auto drum = openConfigSection (config, "drum"); if (drum) drumWaitPeriod = readConfigInt (drum, "wait_period", drumWaitPeriod); @@ -331,11 +332,11 @@ Init () { useTaikoController = readConfigBool (taikoController, "analog", useTaikoController); if (useTaikoController) printf ("Using analog input mode. All the keyboard drum inputs have been disabled.\n"); } - toml_free (config); } - auto keyconfigPath = std::filesystem::current_path () / "keyconfig.toml"; - toml_table_t *keyconfig = openConfig (keyconfigPath); + auto keyconfigPath = std::filesystem::current_path () / "keyconfig.toml"; + std::unique_ptr keyconfig_ptr (openConfig (keyconfigPath), toml_free); + toml_table_t *keyconfig = keyconfig_ptr.get (); if (keyconfig) { SetConfigValue (keyconfig, "EXIT", &EXIT); @@ -359,8 +360,6 @@ Init () { SetConfigValue (keyconfig, "P2_LEFT_RED", &P2_LEFT_RED); SetConfigValue (keyconfig, "P2_RIGHT_RED", &P2_RIGHT_RED); SetConfigValue (keyconfig, "P2_RIGHT_BLUE", &P2_RIGHT_BLUE); - - toml_free (keyconfig); } } } // namespace bnusio diff --git a/src/dllmain.cpp b/src/dllmain.cpp index 9a7fa84..ad64008 100644 --- a/src/dllmain.cpp +++ b/src/dllmain.cpp @@ -100,9 +100,10 @@ DllMain (HMODULE module, DWORD reason, LPVOID reserved) { // This is bad, dont do this // I/O in DllMain can easily cause a deadlock - const char *version = "auto"; - auto configPath = std::filesystem::current_path () / "config.toml"; - toml_table_t *config = openConfig (configPath); + const char *version = "auto"; + auto configPath = std::filesystem::current_path () / "config.toml"; + std::unique_ptr config_ptr (openConfig (configPath), toml_free); + toml_table_t *config = config_ptr.get (); if (config) { auto amauth = openConfigSection (config, "amauth"); if (amauth) { @@ -122,7 +123,6 @@ DllMain (HMODULE module, DWORD reason, LPVOID reserved) { } auto patches = openConfigSection (config, "patches"); if (patches) version = readConfigString (patches, "version", version); - toml_free (config); } if (!strcmp (version, "auto")) { diff --git a/src/patches/cn_jun_2023.cpp b/src/patches/cn_jun_2023.cpp index 91f3eb7..84463cf 100644 --- a/src/patches/cn_jun_2023.cpp +++ b/src/patches/cn_jun_2023.cpp @@ -124,8 +124,9 @@ Init () { INSTALL_HOOK (HaspGetInfo); INSTALL_HOOK (HaspRead); - auto configPath = std::filesystem::current_path () / "config.toml"; - toml_table_t *config = openConfig (configPath); + auto configPath = std::filesystem::current_path () / "config.toml"; + std::unique_ptr config_ptr (openConfig (configPath), toml_free); + toml_table_t *config = config_ptr.get (); if (config) { auto patches = openConfigSection (config, "patches"); if (patches) { @@ -145,7 +146,6 @@ Init () { modeCollabo026 = readConfigBool (cn_jun_2023, "mode_collabo026", modeCollabo026); } } - toml_free (config); } // Apply common config patch diff --git a/src/patches/jp_apr_2023.cpp b/src/patches/jp_apr_2023.cpp index be9bb7b..e2e3bb1 100644 --- a/src/patches/jp_apr_2023.cpp +++ b/src/patches/jp_apr_2023.cpp @@ -48,8 +48,9 @@ Init () { bool sharedAudio = true; bool unlockSongs = true; - auto configPath = std::filesystem::current_path () / "config.toml"; - toml_table_t *config = openConfig (configPath); + auto configPath = std::filesystem::current_path () / "config.toml"; + std::unique_ptr config_ptr (openConfig (configPath), toml_free); + toml_table_t *config = config_ptr.get (); if (config) { auto patches = openConfigSection (config, "patches"); if (patches) { @@ -62,7 +63,6 @@ Init () { sharedAudio = readConfigBool (patches, "shared_audio", sharedAudio); unlockSongs = readConfigBool (patches, "unlock_songs", unlockSongs); } - toml_free (config); } // Apply common config patch diff --git a/src/patches/jp_nov_2020.cpp b/src/patches/jp_nov_2020.cpp index 05a3610..a1a13b1 100644 --- a/src/patches/jp_nov_2020.cpp +++ b/src/patches/jp_nov_2020.cpp @@ -52,8 +52,9 @@ Init () { bool sharedAudio = true; bool unlockSongs = true; - auto configPath = std::filesystem::current_path () / "config.toml"; - toml_table_t *config = openConfig (configPath); + auto configPath = std::filesystem::current_path () / "config.toml"; + std::unique_ptr config_ptr (openConfig (configPath), toml_free); + toml_table_t *config = config_ptr.get (); if (config) { auto patches = openConfigSection (config, "patches"); if (patches) { @@ -66,7 +67,6 @@ Init () { sharedAudio = readConfigBool (patches, "shared_audio", sharedAudio); unlockSongs = readConfigBool (patches, "unlock_songs", unlockSongs); } - toml_free (config); } // Apply common config patch