backend: ensure that server side releases/frees shm segment on exit

We were leaking one for every job run.

Signed-off-by: Jens Axboe <axboe@kernel.dk>
diff --git a/init.c b/init.c
index a04198f..cf105a3 100644
--- a/init.c
+++ b/init.c
@@ -207,7 +207,7 @@
 	},
 };
 
-static void free_shm(void)
+void free_threads_shm(void)
 {
 	struct shmid_ds sbuf;
 
@@ -215,11 +215,19 @@
 		void *tp = threads;
 
 		threads = NULL;
+		shmdt(tp);
+		shmctl(shm_id, IPC_RMID, &sbuf);
+		shm_id = -1;
+	}
+}
+
+void free_shm(void)
+{
+	if (threads) {
 		file_hash_exit();
 		flow_exit();
 		fio_debug_jobp = NULL;
-		shmdt(tp);
-		shmctl(shm_id, IPC_RMID, &sbuf);
+		free_threads_shm();
 	}
 
 	scleanup();