From 526a91d2954492cc8e23c2c4c8def2a053af7c20 Mon Sep 17 00:00:00 2001 From: Prcuvu Date: Thu, 5 Apr 2018 16:10:11 +0800 Subject: [PATCH] fix: fix defects according to Coverity Scan --- RimeWithWeasel/RimeWithWeasel.cpp | 2 +- WeaselDeployer/Configurator.cpp | 1 + WeaselDeployer/SwitcherSettingsDialog.cpp | 4 +++- WeaselServer/WeaselService.cpp | 4 ++++ WeaselSetup/imesetup.cpp | 9 ++++++--- include/WeaselCommon.h | 2 +- 6 files changed, 16 insertions(+), 6 deletions(-) diff --git a/RimeWithWeasel/RimeWithWeasel.cpp b/RimeWithWeasel/RimeWithWeasel.cpp index 188a3591c..25b6bd0db 100644 --- a/RimeWithWeasel/RimeWithWeasel.cpp +++ b/RimeWithWeasel/RimeWithWeasel.cpp @@ -433,7 +433,7 @@ bool RimeWithWeaselHandler::_Respond(UINT session_id, EatLine eat) RimeFreeCommit(&commit); } - bool is_composing; + bool is_composing = false; RIME_STRUCT(RimeStatus, status); if (RimeGetStatus(session_id, &status)) { diff --git a/WeaselDeployer/Configurator.cpp b/WeaselDeployer/Configurator.cpp index 5704f7743..6d49b2ca0 100644 --- a/WeaselDeployer/Configurator.cpp +++ b/WeaselDeployer/Configurator.cpp @@ -202,6 +202,7 @@ int Configurator::SyncUserData() { if (!rime->sync_user_data()) { LOG(ERROR) << "Error synching user data."; + CloseHandle(hMutex); return 1; } rime->join_maintenance_thread(); diff --git a/WeaselDeployer/SwitcherSettingsDialog.cpp b/WeaselDeployer/SwitcherSettingsDialog.cpp index 968f8b442..57057e0d8 100644 --- a/WeaselDeployer/SwitcherSettingsDialog.cpp +++ b/WeaselDeployer/SwitcherSettingsDialog.cpp @@ -109,10 +109,12 @@ LRESULT SwitcherSettingsDialog::OnOK(WORD, WORD code, HWND, BOOL&) { } } if (count == 0) { - MessageBox(L"至少要選用一項吧。", L"小狼毫不是這般用法", MB_OK | MB_ICONEXCLAMATION); + MessageBox(_T("至少要選用一項吧。"), _T("小狼毫不是這般用法"), MB_OK | MB_ICONEXCLAMATION); + delete selection; return 0; } api_->select_schemas(settings_, selection, count); + delete selection; } EndDialog(code); return 0; diff --git a/WeaselServer/WeaselService.cpp b/WeaselServer/WeaselService.cpp index 72eccce4d..cdb5de899 100644 --- a/WeaselServer/WeaselService.cpp +++ b/WeaselServer/WeaselService.cpp @@ -46,6 +46,10 @@ WeaselService::WeaselService( WeaselService::~WeaselService() { + if (_stoppedEvent != NULL) + { + CloseHandle(_stoppedEvent); + } } BOOL WeaselService::Run(WeaselService &serv) diff --git a/WeaselSetup/imesetup.cpp b/WeaselSetup/imesetup.cpp index 0f5c3cb66..cb446c776 100644 --- a/WeaselSetup/imesetup.cpp +++ b/WeaselSetup/imesetup.cpp @@ -162,11 +162,14 @@ int register_ime(const wpath& ime_path, bool register_ime, bool is_wow64, bool h DWORD len = sizeof(imeFile); DWORD type = 0; ret = RegQueryValueEx(hSubKey, L"Ime File", NULL, &type, (LPBYTE)imeFile, &len); - RegCloseKey(hSubKey); - if (_wcsicmp(imeFile, L"weasel.ime") == 0) + if (ret = ERROR_SUCCESS) { - hKL = (HKL)k; // already there + if (_wcsicmp(imeFile, L"weasel.ime") == 0) + { + hKL = (HKL)k; // already there + } } + RegCloseKey(hSubKey); } else { diff --git a/include/WeaselCommon.h b/include/WeaselCommon.h index 4c9b93902..e361d2cfe 100644 --- a/include/WeaselCommon.h +++ b/include/WeaselCommon.h @@ -29,7 +29,7 @@ namespace weasel struct TextAttribute { - TextAttribute() {} + TextAttribute() : type(NONE) {} TextAttribute(int _start, int _end, TextAttributeType _type) : range(_start, _end), type(_type) {} TextRange range; TextAttributeType type;