pespin has submitted this change. ( https://gerrit.osmocom.org/c/libosmocore/+/39072?usp=email )
Change subject: osmo_io: segmented_read: Avoid triggering read events if user unregisters ......................................................................
osmo_io: segmented_read: Avoid triggering read events if user unregisters
The user code doesn't expect to receive any more read cb events after unregistering the FD. Avoid keep calling the read cb if several entire messages were received at once in a single tcp chunk.
Related: SYS#7063 Change-Id: Id2199b9aa805cc7e7793c1a8aecd10b61f2b4c90 --- M src/core/osmo_io.c 1 file changed, 9 insertions(+), 1 deletion(-)
Approvals: fixeria: Looks good to me, but someone else must approve osmith: Looks good to me, but someone else must approve pespin: Looks good to me, approved Jenkins Builder: Verified
diff --git a/src/core/osmo_io.c b/src/core/osmo_io.c index c61c8e9..d1767d2 100644 --- a/src/core/osmo_io.c +++ b/src/core/osmo_io.c @@ -340,8 +340,16 @@ do { pending = NULL; res = iofd_handle_segmentation(iofd, msg, &pending); - if (res != IOFD_SEG_ACT_DEFER || rc < 0) + if (res != IOFD_SEG_ACT_DEFER || rc < 0) { iofd->io_ops.read_cb(iofd, rc, msg); + /* The user could unregister/close the iofd during read_cb() above. + * Once that's done, it doesn't expect to receive any more events, + * so discard it: */ + if (!IOFD_FLAG_ISSET(iofd, IOFD_FLAG_FD_REGISTERED)) { + msgb_free(pending); + return; + } + } if (res == IOFD_SEG_ACT_HANDLE_MORE) msg = pending; } while (res == IOFD_SEG_ACT_HANDLE_MORE);