summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorReuben Thomas <rrt@sc3d.org>2020-07-29 17:59:01 +0100
committerReuben Thomas <rrt@sc3d.org>2020-07-29 20:44:37 +0100
commit6b14da01c9f6e4ef2f35bbfd9bb307e5f7fada59 (patch)
tree35d6df3767794cb52756d6a0c2920fd0c4f4e3f3
parent7e8fa6eba1d6717f954a7e4397a658999f54fe98 (diff)
downloadenchant-6b14da01c9f6e4ef2f35bbfd9bb307e5f7fada59.tar.gz
providers/enchant_nuspell.cpp: fix a few leaks
A malloced char * was being converted to std::string without freeing the char * in a few places.
-rw-r--r--providers/enchant_nuspell.cpp10
1 files changed, 7 insertions, 3 deletions
diff --git a/providers/enchant_nuspell.cpp b/providers/enchant_nuspell.cpp
index e97a3d3..1f10918 100644
--- a/providers/enchant_nuspell.cpp
+++ b/providers/enchant_nuspell.cpp
@@ -74,8 +74,9 @@ NuspellChecker::checkWord(const char *utf8Word, size_t len)
{
// the 8-bit encodings use precomposed forms
char *normalizedWord = g_utf8_normalize (utf8Word, len, G_NORMALIZE_NFC);
-
- return nuspell.spell(string(normalizedWord));
+ string s(normalizedWord);
+ g_free(normalizedWord);
+ return nuspell.spell(s);
}
char**
@@ -83,8 +84,10 @@ NuspellChecker::suggestWord(const char* const utf8Word, size_t len, size_t *nsug
{
// the 8-bit encodings use precomposed forms
char *normalizedWord = g_utf8_normalize (utf8Word, len, G_NORMALIZE_NFC);
+ string s(normalizedWord);
+ g_free(normalizedWord);
auto suggestions = vector<string>();
- nuspell.suggest(string(normalizedWord), suggestions);
+ nuspell.suggest(s, suggestions);
if (suggestions.empty())
return nullptr;
*nsug = suggestions.size();
@@ -254,6 +257,7 @@ NuspellChecker::requestDictionary(const char *szLang)
if (!s_fileExists(aff))
return false;
auto path = string(dic);
+ free(dic);
if (path.size() >= 4 && path.compare(path.size() - 4, 4, ".dic") == 0)
path.erase(path.size() - 4);
else