Permalink
Browse files

Return a newly allocated string from java_completer

This is required since java will manage that string's lifecycle. Not
doing this will end up with a double free.
  • Loading branch information...
aclemons committed Jun 28, 2017
1 parent aaeeca8 commit 2daaa37281ec82a469ef4e42ee7758e3fec6d6f4
Showing with 15 additions and 2 deletions.
  1. +2 −2 src/native/org_gnu_readline_Readline.c
  2. +1 −0 src/test/BatsTestReader.java
  3. +12 −0 src/test/test.bats
@@ -578,12 +578,12 @@ const char *java_completer(char *text, int state) {
completion = (*jniEnv)->CallObjectMethod(jniEnv, jniObject,
jniMethodId, jtext, state);
if (!completion) {
return ((const char *)NULL);
return ((const char *) NULL);
}
line = fromjstring(jniEnv, completion);
return line;
return strdup(line);
}
#endif
@@ -42,6 +42,7 @@ public static void main(final String[] args) throws IOException {
Readline.load(library);
Readline.initReadline("BatsTestReader");
Readline.setCompleter(new TestCompleter());
final String prompt;
if (args.length > 1) {
View
@@ -82,6 +82,10 @@ assert_history() {
[ "$output" = "$2" ]
}
assert_completion() {
[ "$(printf "L\t\n" | LANG="$2" "$JAVA_HOME/bin/java" -Dfile.encoding="$3" -Djava.library.path="$LIBDIR" -cp "$LIBDIR/libreadline-java.jar" test.BatsTestReader "$1" | sed -n '1p')" = "bats> Linux " ]
}
@test "GnuReadline handles simple ascii prompt" {
if ! is_readline ; then
skip "java-readline not built with GnuReadline support"
@@ -351,3 +355,11 @@ assert_history() {
assert_var "Editline" "RL_LINE_BUFFER" "$(printf "%b" "Hello World\xf0\x9f\x8c\x8b")" "en_US.UTF-8" "UTF-8"
}
@test "GnuReadline handles simple ascii completion" {
if ! is_readline ; then
skip "java-readline not built with GnuReadline support"
fi
assert_completion "GnuReadline" "en_US.UTF-8" "UTF-8"
}

0 comments on commit 2daaa37

Please sign in to comment.