logging.c: Sanitize calls to osmo_fd_unregister()

It makes no sense to call osmo_fd_unregister() on a negative fd.
Let's also make sure we set fd to negative value after unregistering +
closing, even if the struct is going to be freed afterwards.

Change-Id: I0790a63e603028c11cc475d483c6528e4d9aa9ab
diff --git a/src/core/logging.c b/src/core/logging.c
index bcfe318..3095f0d 100644
--- a/src/core/logging.c
+++ b/src/core/logging.c
@@ -1161,6 +1161,7 @@
 	if (target->type == LOG_TGT_TYPE_FILE) {
 		osmo_fd_unregister(&wq->bfd);
 		close(wq->bfd.fd);
+		wq->bfd.fd = -1;
 	}
 
 	/* release the queue itself */
@@ -1327,8 +1328,8 @@
 		}
 		wq = target->tgt_file.wqueue;
 		if (wq) {
-			osmo_fd_unregister(&wq->bfd);
 			if (wq->bfd.fd >= 0) {
+				osmo_fd_unregister(&wq->bfd);
 				if (target->type == LOG_TGT_TYPE_FILE)
 					close(wq->bfd.fd);
 				wq->bfd.fd = -1;
@@ -1375,8 +1376,8 @@
 			return -errno;
 	} else {
 		wq = target->tgt_file.wqueue;
-		osmo_fd_unregister(&wq->bfd);
 		if (wq->bfd.fd >= 0) {
+			osmo_fd_unregister(&wq->bfd);
 			close(wq->bfd.fd);
 			wq->bfd.fd = -1;
 		}