Skip to content

Commit

Permalink
Merge pull request #249 from rrthomas/master
Browse files Browse the repository at this point in the history
Fix a couple of space leaks
  • Loading branch information
rrthomas authored Aug 22, 2020
2 parents 583e9e8 + 2e8b0af commit cb8c758
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 19 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ Makefile
Makefile.in
/aclocal.m4
/autom4te.cache
/build-aux
/compile
/configure
/config.*
Expand Down
29 changes: 15 additions & 14 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
os: linux
language: cpp

dist: bionic

addons:
Expand All @@ -17,27 +17,28 @@ addons:
- libunittest++-dev
- hunspell-fr
- libnuspell-dev
homebrew:
# Note: aspell should work on macOS, but has been removed because one of
# the tests fails; see https://github.com/Homebrew/homebrew-core/issues/4097
packages:
- glib
- dbus-glib
- hspell
- hunspell
- libvoikko
- unittest-cpp
update: true

env:
global:
- VERBOSE=1 # Get test logs in Travis logs

matrix:
jobs:
include:
- os: linux
env:
- CONFIGURE_ARGS=("CFLAGS=\"-g3 -fsanitize=address -fsanitize=undefined\"" "LDFLAGS=\"-fsanitize=address -fsanitize=undefined\"")
- ASAN=yes
- os: osx

before_install:
# Note: aspell should work on macOS, but has been removed from the next
# line because one of the tests fails; see
# https://github.com/Homebrew/homebrew-core/issues/40976
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew install dbus-glib hspell hunspell libvoikko unittest-cpp ; fi

script:
- ./bootstrap
- ./configure --enable-relocatable --with-zemberek=check "${CONFIGURE_ARGS[@]}"
- make
- make distcheck
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then sudo locale-gen fr_FR.UTF-8; env LANG=fr_FR.UTF-8 make check ; fi
- ./build-aux/travis-build.sh
6 changes: 6 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
2.2.9 (July 29, 2020)
---------------------

Fix a couple of space leaks in the Nuspell back end (thanks, ASAN).


2.2.8 (February 27, 2020)
-------------------------

Expand Down
15 changes: 15 additions & 0 deletions build-aux/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/bootstrap.in
/compile
/config.guess
/config.sub
/depcomp
/extract-trace
/funclib.sh
/inline-source
/install-sh
/ltmain.sh
/mdate-sh
/missing
/options-parser
/test-driver
/texinfo.tex
17 changes: 17 additions & 0 deletions build-aux/travis-build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash
# Build on Travis
# Written by Reuben Thomas 2020.
# This file is in the public domain.

set -e

./bootstrap
CONFIGURE_ARGS=(--enable-relocatable --with-zemberek=check)
if [[ "$ASAN" == "yes" ]]; then
CONFIGURE_ARGS+=(CFLAGS="-g3 -fsanitize=address -fsanitize=undefined" LDFLAGS="-fsanitize=address -fsanitize=undefined")
fi
./configure --enable-silent-rules "${CONFIGURE_ARGS[@]}"
make
make distcheck

if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then sudo locale-gen fr_FR.UTF-8; env LANG=fr_FR.UTF-8 make check ; fi
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
AC_INIT([enchant],[2.2.8])
AC_INIT([enchant],[2.2.9])
AC_CONFIG_SRCDIR(src/enchant.h)
AC_CONFIG_AUX_DIR([build-aux])
AM_INIT_AUTOMAKE([subdir-objects])
Expand Down
10 changes: 7 additions & 3 deletions providers/enchant_nuspell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,17 +74,20 @@ 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**
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();
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit cb8c758

Please sign in to comment.