diff --git a/src/groonga.c b/src/groonga.c
index 56cfd68..01dadac 100644
--- a/src/groonga.c
+++ b/src/groonga.c
@@ -1849,7 +1849,7 @@ main(int argc, char **argv)
     break;
   }
 #ifdef WITH_LIBEDIT
-  if (batchmode) {
+  if (!batchmode) {
     history_end(elh);
     el_end(el);
   }

