Commit Diff


commit - 34f87d66a849d11bdcfa5326ddfcb354d05d077d
commit + adebfe7ca6a3738adf2246bcc87552914348c30a
blob - bafe39fddfcb8ac9a38af4e2ef813d393ea34044
blob + 2ed1f71cc3fc3fc56c6cbd83739a26eaa6cbcdd2
--- opensmtpd.c
+++ opensmtpd.c
@@ -909,12 +909,12 @@ osmtpd_run(void)
 {
 	size_t i = 0;
 	int registered = 0;
-	/* Doesn't leak, since it needs to exists until the application ends. */
+	struct event_base *evbase;
 	struct io *io_stdin;
 	struct osmtpd_callback *hidenity = NULL, *eidentity = NULL;
 	struct osmtpd_callback *ridentity = NULL;
 
-	event_init();
+	evbase = event_init();
 
 	if ((io_stdin = io_new()) == NULL ||
 	    (io_stdout = io_new()) == NULL)
@@ -978,6 +978,9 @@ osmtpd_run(void)
 	ready = 1;
 
 	event_dispatch();
+	io_free(io_stdin);
+	io_free(io_stdout);
+	event_base_free(evbase);
 }
 
 __dead void
@@ -1020,8 +1023,10 @@ osmtpd_newline(struct io *io, int ev, __unused void *a
 	char *end;
 	size_t i;
 
-	if (ev == IO_DISCONNECTED)
-		exit(0);
+	if (ev == IO_DISCONNECTED) {
+		event_loopexit(0);
+		return;
+	}
 	if (ev != IO_DATAIN)
 		return;
 	while ((line = io_getline(io, &linelen)) != NULL) {