pespin has uploaded this change for review.

View Change

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
---
M src/core/logging.c
1 file changed, 16 insertions(+), 2 deletions(-)

git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/09/31909/1
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;
}

To view, visit change 31909. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: I0790a63e603028c11cc475d483c6528e4d9aa9ab
Gerrit-Change-Number: 31909
Gerrit-PatchSet: 1
Gerrit-Owner: pespin <pespin@sysmocom.de>
Gerrit-MessageType: newchange