diff options
author | George Hazan <ghazan@miranda.im> | 2018-01-15 15:30:14 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2018-01-15 15:30:14 +0300 |
commit | 05d6c1473c320e1f6f5c489983f64085d26504f5 (patch) | |
tree | 7f634c6e0f9feacb65b1e99eee7f02f1dee4ee18 /plugins | |
parent | aa860d8a7b584886f7606369fbddd85e6db5a500 (diff) |
fix for various memory problems in SpellChecker
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/SpellChecker/src/ardialog.cpp | 11 | ||||
-rw-r--r-- | plugins/SpellChecker/src/autoreplace.cpp | 11 | ||||
-rw-r--r-- | plugins/SpellChecker/src/stdafx.h | 6 | ||||
-rw-r--r-- | plugins/SpellChecker/src/utils.cpp | 19 |
4 files changed, 15 insertions, 32 deletions
diff --git a/plugins/SpellChecker/src/ardialog.cpp b/plugins/SpellChecker/src/ardialog.cpp index a5948d3ec7..eec0687100 100644 --- a/plugins/SpellChecker/src/ardialog.cpp +++ b/plugins/SpellChecker/src/ardialog.cpp @@ -98,9 +98,7 @@ static LRESULT CALLBACK OnlyCharsEditProc(HWND hwnd, UINT msg, WPARAM wParam, LP case WM_PASTE:
wchar_t text[256];
GetWindowText(hwnd, text, _countof(text));
-
- scoped_free<wchar_t> dest = data->dict->autoReplace->filterText(text);
- SetWindowText(hwnd, dest);
+ SetWindowText(hwnd, ptrW(data->dict->autoReplace->filterText(text)));
break;
}
@@ -170,10 +168,9 @@ static INT_PTR CALLBACK AddReplacementDlgProc(HWND hwndDlg, UINT msg, WPARAM wPa SendDlgItemMessage(hwndDlg, IDC_OLD, EM_LIMITTEXT, 256, 0);
SendDlgItemMessage(hwndDlg, IDC_NEW, EM_LIMITTEXT, 256, 0);
- if (!data->find.empty()) {
- scoped_free<wchar_t> tmp = data->dict->autoReplace->filterText(data->find.c_str());
- SetDlgItemText(hwndDlg, IDC_OLD, tmp);
- }
+ if (!data->find.empty())
+ SetDlgItemText(hwndDlg, IDC_OLD, ptrW(data->dict->autoReplace->filterText(data->find.c_str())));
+
if (!data->replace.empty())
SetDlgItemText(hwndDlg, IDC_NEW, data->replace.c_str());
diff --git a/plugins/SpellChecker/src/autoreplace.cpp b/plugins/SpellChecker/src/autoreplace.cpp index ea3449e56d..b111862c3b 100644 --- a/plugins/SpellChecker/src/autoreplace.cpp +++ b/plugins/SpellChecker/src/autoreplace.cpp @@ -129,7 +129,7 @@ BOOL AutoReplaceMap::isWordChar(wchar_t c) wchar_t* AutoReplaceMap::autoReplace(const wchar_t * word)
{
- scoped_free<wchar_t> from = wcslwr(wcsdup(word));
+ ptrW from(wcslwr(mir_wstrdup(word)));
if (m_replacements.find(from.get()) == m_replacements.end())
return nullptr;
@@ -140,7 +140,7 @@ wchar_t* AutoReplaceMap::autoReplace(const wchar_t * word) if (ar.useVariables)
to = variables_parsedup((wchar_t *)ar.replace.c_str(), (wchar_t *)word, NULL);
else
- to = wcsdup(ar.replace.c_str());
+ to = mir_wstrdup(ar.replace.c_str());
// Wich case to use?
size_t len = mir_wstrlen(word);
@@ -166,7 +166,7 @@ wchar_t* AutoReplaceMap::autoReplace(const wchar_t * word) wchar_t* AutoReplaceMap::filterText(const wchar_t *find)
{
- wchar_t *ret = wcsdup(find);
+ wchar_t *ret = mir_wstrdup(find);
int len = mir_wstrlen(ret);
int pos = 0;
for (int i = 0; i < len; i++)
@@ -178,8 +178,7 @@ wchar_t* AutoReplaceMap::filterText(const wchar_t *find) void AutoReplaceMap::add(const wchar_t * aFrom, const wchar_t * to, BOOL useVariables)
{
- scoped_free<wchar_t> from = filterText(aFrom);
-
+ ptrW from(filterText(aFrom));
m_replacements[from.get()] = AutoReplacement(to, useVariables);
writeAutoReplaceMap();
@@ -196,7 +195,7 @@ void AutoReplaceMap::setMap(const map<std::wstring, AutoReplacement> &replacemen map<std::wstring, AutoReplacement>::const_iterator it = replacements.begin();
for (; it != replacements.end(); it++) {
- scoped_free<wchar_t> from = filterText(it->first.c_str());
+ ptrW from(filterText(it->first.c_str()));
m_replacements[from.get()] = it->second;
}
diff --git a/plugins/SpellChecker/src/stdafx.h b/plugins/SpellChecker/src/stdafx.h index 2b7fd394f8..033c84e806 100644 --- a/plugins/SpellChecker/src/stdafx.h +++ b/plugins/SpellChecker/src/stdafx.h @@ -54,9 +54,7 @@ using namespace std; #include <m_spellchecker.h>
#include <../../utils/mir_options.h>
-//#include <../../utils/tstring.h>
#include <../../utils/utf8_helpers.h>
-#include <../../utils/scope.h>
#include <hunspell.hpp>
@@ -130,7 +128,7 @@ struct Dialog static BOOL CenterParent(HWND hwnd);
wchar_t *lstrtrim(wchar_t *str);
-BOOL lstreq(wchar_t *a, wchar_t *b, size_t len = -1);
+
inline BOOL IsNumber(wchar_t c)
{
return c >= '0' && c <= '9';
@@ -152,7 +150,7 @@ LRESULT CALLBACK MenuWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam); void ModifyIcon(Dialog *dlg);
BOOL GetWordCharRange(Dialog *dlg, CHARRANGE &sel, wchar_t *text, size_t text_len, int &first_char);
-wchar_t *GetWordUnderPoint(Dialog *dlg, POINT pt, CHARRANGE &sel);
+wchar_t* GetWordUnderPoint(Dialog *dlg, POINT pt, CHARRANGE &sel);
int GetClosestLanguage(wchar_t *lang_name);
diff --git a/plugins/SpellChecker/src/utils.cpp b/plugins/SpellChecker/src/utils.cpp index 57f29e47ff..e87ab53616 100644 --- a/plugins/SpellChecker/src/utils.cpp +++ b/plugins/SpellChecker/src/utils.cpp @@ -1000,7 +1000,7 @@ BOOL GetWordCharRange(Dialog *dlg, CHARRANGE &sel, wchar_t *text, size_t text_le return has_valid_char;
}
-wchar_t *GetWordUnderPoint(Dialog *dlg, POINT pt, CHARRANGE &sel)
+wchar_t* GetWordUnderPoint(Dialog *dlg, POINT pt, CHARRANGE &sel)
{
// Get text
if (dlg->re->GetTextLength() <= 0)
@@ -1018,10 +1018,9 @@ wchar_t *GetWordUnderPoint(Dialog *dlg, POINT pt, CHARRANGE &sel) // copy the word
text[sel.cpMax - first_char] = '\0';
- return wcsdup(&text[sel.cpMin - first_char]);
+ return mir_wstrdup(&text[sel.cpMin - first_char]);
}
-
void AppendSubmenu(HMENU hMenu, HMENU hSubMenu, wchar_t *name)
{
MENUITEMINFO mii = { 0 };
@@ -1129,7 +1128,7 @@ void FoundWrongWord(wchar_t *word, CHARRANGE pos, void *param) p->count++;
- AddMenuForWord(p->dlg, wcsdup(word), pos, p->dlg->hWrongWordsSubMenu, TRUE, WORD_MENU_ID_BASE * p->count);
+ AddMenuForWord(p->dlg, word, pos, p->dlg->hWrongWordsSubMenu, TRUE, WORD_MENU_ID_BASE * p->count);
}
void AddItemsToMenu(Dialog *dlg, HMENU hMenu, POINT pt, HWND hwndOwner)
@@ -1174,7 +1173,7 @@ void AddItemsToMenu(Dialog *dlg, HMENU hMenu, POINT pt, HWND hwndOwner) }
else {
CHARRANGE sel;
- wchar_t *word = GetWordUnderPoint(dlg, pt, sel);
+ ptrW word(GetWordUnderPoint(dlg, pt, sel));
if (word != nullptr && !dlg->lang->spell(word)) {
InsertMenu(hMenu, 0, MF_BYPOSITION | MF_SEPARATOR, 0, nullptr);
AddMenuForWord(dlg, word, sel, hMenu, FALSE, WORD_MENU_ID_BASE);
@@ -1559,13 +1558,3 @@ wchar_t* lstrtrim(wchar_t *str) return str;
}
-
-BOOL lstreq(wchar_t *a, wchar_t *b, size_t len)
-{
- a = CharLower(wcsdup(a));
- b = CharLower(wcsdup(b));
- BOOL ret = len ? !wcsncmp(a, b, len) : !mir_wstrcmp(a, b);
- free(a);
- free(b);
- return ret;
-}
|