OSDN Git Service

[Qt][JOY_THREAD] Fix memory leak when plug/unplug joystick.
authorK.Ohta <whatisthis.sowhat@gmail.com>
Tue, 24 Sep 2019 22:59:37 +0000 (07:59 +0900)
committerK.Ohta <whatisthis.sowhat@gmail.com>
Tue, 24 Sep 2019 22:59:37 +0000 (07:59 +0900)
source/src/config.cpp
source/src/qt/gui/joy_thread.cpp

index d1cc909..ca30253 100644 (file)
@@ -491,7 +491,6 @@ void DLL_PREFIX load_config(const _TCHAR *config_path)
                config.logwindow_width = MyGetPrivateProfileInt(_T("Qt"), _T("LogWindowWidth"), 800, config_path);
                config.logwindow_height = MyGetPrivateProfileInt(_T("Qt"), _T("LogWindowHeight"), 500, config_path);
                // Assigning joysticks.
-#if 0
                for(i = 0; i < 16; i++) {
                        _TCHAR name[256];
                        my_stprintf_s(name, 255, _T("AssignedJoystick%d"), i + 1);
@@ -499,8 +498,6 @@ void DLL_PREFIX load_config(const _TCHAR *config_path)
                                                                          config.assigned_joystick_name[i], 255, config_path);
                        printf("%d->%s\n", i, config.assigned_joystick_name[i]);
                }
-#endif
-               
                // Movie load/save.
                config.video_width   = MyGetPrivateProfileInt(_T("Qt"), _T("VideoWidth"), 640, config_path);
                if(config.video_width < 128) config.video_width = 128;
index 08bdb09..3bfdde5 100644 (file)
@@ -103,7 +103,7 @@ void JoyThreadClass::joystick_plugged(int num)
                        names[num] = QString::fromUtf8(SDL_GameControllerNameForIndex(num));
                        csp_logger->debug_log(CSP_LOG_INFO, CSP_LOG_TYPE_JOYSTICK, "JoyThread : Controller %d : %s : is plugged.", num, names[num].toUtf8().constData());
                        strncpy(p_config->assigned_joystick_name[num], names[num].toUtf8().constData(),
-                                       (sizeof(p_config->assigned_joystick_name)  / sizeof(char)) - 1);
+                                       (sizeof(p_config->assigned_joystick_name[num])  / sizeof(char)) - 1);
                        joy_num[num] = num;
                }
        } else 
@@ -119,7 +119,7 @@ void JoyThreadClass::joystick_plugged(int num)
                                        names[i] = QString::fromUtf8(SDL_JoystickNameForIndex(num));
                                        csp_logger->debug_log(CSP_LOG_INFO, CSP_LOG_TYPE_JOYSTICK, "JoyThread : Joystick %d : %s : is plugged.", num, names[i].toUtf8().data());
                                        strncpy(p_config->assigned_joystick_name[num], names[num].toUtf8().constData(),
-                                                       (sizeof(p_config->assigned_joystick_name)  / sizeof(char)) - 1);
+                                                       (sizeof(p_config->assigned_joystick_name[num])  / sizeof(char)) - 1);
                                        break;
                                }
                        }