about summary refs log tree commit diff
diff options
context:
space:
mode:
-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();