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
-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();
4926009853d0db&follow=1'>Add The Stone SkyJune McEnroe 2020-03-08Publish "How I Relay Chat"June McEnroe 2020-03-03Don't use $ inside $(())June McEnroe 2020-03-03Remove setoptJune McEnroe 2020-03-03Use getopts in shell scriptsJune McEnroe 2020-02-27Style %T outside of Rs in italicJune McEnroe 2020-02-26Add Fierce Femmes and Notorious LiarsJune McEnroe 2020-02-23Add This Is How You Lose the Time WarJune McEnroe 2020-02-22Add See Ya LaterJune McEnroe 2020-02-20Remove wiki scriptJune McEnroe 2020-02-19Add The Obelisk GateJune McEnroe 2020-02-17Add Four Tet — HandsJune McEnroe 2020-02-12Simplify macOS notify-sendJune McEnroe 2020-02-12Add imbox and notemap to pageJune McEnroe 2020-02-12Collapse simple linksJune McEnroe 2020-02-12Move catgirl up the pageJune McEnroe 2020-02-12Update catgirl pty grabJune McEnroe 2020-02-12Link to cgit /about pages where appropriateJune McEnroe 2020-02-11Separate LINKS from BINS for html to workJune McEnroe 2020-02-11Add margin to Bl-bullet itemsJune McEnroe 2020-02-10Match URLs inside parens or with paired parens insideJune McEnroe 2020-02-10Duplicate effective URL before passing it back to curlJune McEnroe 2020-02-09Add To Be Taught, If FortunateJune McEnroe 2020-02-04Add The Future of Another TimelineJune McEnroe 2020-01-31Reorganize the Makefile for the umpteenth timeJune McEnroe 2020-01-28Change scout sensitivity to 1.4June McEnroe 2020-01-28Import shows.txtJune McEnroe