summary refs log tree commit diff
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2019-12-28 18:27:21 -0500
committerJune McEnroe <june@causal.agency>2019-12-28 18:27:21 -0500
commit36298c7ba6872cb3088223bc7701db79f90a8349 (patch)
treeb070e438b330439beeab8df30357f1fcb32679ba
parentMove querySearch code around (diff)
downloadlitterbox-36298c7ba6872cb3088223bc7701db79f90a8349.tar.gz
litterbox-36298c7ba6872cb3088223bc7701db79f90a8349.zip
Call tls_close and dbClose in atexit
Diffstat (limited to '')
-rw-r--r--litterbox.c11
1 files changed, 7 insertions, 4 deletions
diff --git a/litterbox.c b/litterbox.c
index 8ba0923..5924680 100644
--- a/litterbox.c
+++ b/litterbox.c
@@ -549,8 +549,6 @@ static void handlePing(struct Message *msg) {
 
 static void handleError(struct Message *msg) {
 	require(msg, false, 1);
-	tls_close(client);
-	dbClose();
 	errx(EX_UNAVAILABLE, "%s", msg->params[0]);
 }
 
@@ -600,11 +598,15 @@ static void handle(struct Message msg) {
 	}
 }
 
+static void atExit(void) {
+	if (client) tls_close(client);
+	dbClose();
+}
+
 static void quit(int sig) {
 	(void)sig;
 	format("QUIT\r\n");
-	tls_close(client);
-	dbClose();
+	atExit();
 	_exit(EX_OK);
 }
 
@@ -645,6 +647,7 @@ int main(int argc, char *argv[]) {
 	int flags = SQLITE_OPEN_READWRITE;
 	if (init) flags |= SQLITE_OPEN_CREATE;
 	dbFind(path, flags);
+	atexit(atExit);
 
 	if (init) {
 		dbInit();