diff --git a/cli/rtbuf_cli.c b/cli/rtbuf_cli.c
index 2860737..c05c32b 100644
--- a/cli/rtbuf_cli.c
+++ b/cli/rtbuf_cli.c
@@ -305,6 +305,7 @@ int rtbuf_cli_exit (int argc, const char *argv[])
(void) argc;
(void) argv;
rtbuf_cli_stop();
+ librtbuf_shutdown();
close(0);
exit(0);
return 0;
diff --git a/cli/rtbuf_cli_main.c b/cli/rtbuf_cli_main.c
index 4b52d71..6145072 100644
--- a/cli/rtbuf_cli_main.c
+++ b/cli/rtbuf_cli_main.c
@@ -27,6 +27,7 @@ int main (int argc, char *argv[])
repl_init();
rtbuf_cli_args(argc, argv);
res = repl();
+ rtbuf_cli_stop();
librtbuf_shutdown();
return res;
}