pespin has uploaded this change for review. ( https://gerrit.osmocom.org/c/libosmocore/+/31903 )
Change subject: select.c: osmo-fd_unregister(): Avoid assert hit with old buggy users of the API ......................................................................
select.c: osmo-fd_unregister(): Avoid assert hit with old buggy users of the API
Change-Id: If77b84d603a42a216d550d9708eb62f645634a61 --- M src/core/select.c 1 file changed, 19 insertions(+), 3 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/03/31903/1
diff --git a/src/core/select.c b/src/core/select.c index ea8c654..924356a 100644 --- a/src/core/select.c +++ b/src/core/select.c @@ -223,13 +223,20 @@ * osmo_fd_is_registered() */ unregistered_count++; llist_del(&fd->list); - OSMO_ASSERT(fd->fd >= 0); - OSMO_ASSERT(fd->fd <= maxfd); - osmo_fd_lookup.table[fd->fd] = NULL; #ifndef FORCE_IO_SELECT g_poll.num_registered--; #endif /* FORCE_IO_SELECT */
+ if (OSMO_UNLIKELY(fd->fd < 0 || fd->fd > maxfd)) { + /* Some old users used to incorrectly set fd = -1 *before* calling osmo_unregister(). + * Hence, in order to keep backward compatibility it's not possible to assert() here. + * Instead, print an error message since this is actually a bug in the API user. */ + fprintf(stderr, "osmo_fd_unregister(fd=%u) out of expected range (0..%u), fix your code!!!\n", + fd->fd, maxfd); + return; + } + + osmo_fd_lookup.table[fd->fd] = NULL; /* If existent, free any statistical data */ osmo_stats_tcp_osmo_fd_unregister(fd); }