pespin submitted this change.
osmo_io: Keep msgb ownership internal during segmentation until read_cb
Until dispatched to the user over read_cb(), the msgb is considered to
be not-ready-for-user and hence it's kept owned by the iofd.
This resembles more the actual expected parentship tree, since
iofd->pending is freed by osmo_io internally in osmo_iofd_close().
More importat, which should cause less trouble if for instance user of
osmo_iofd wishes to reparent the osmo_io and then free the previous ctx
it passed during osmo_iofd_setup().
Change-Id: I4f41153948b7f1568c7499db53b9620bf2dd9ac4
---
M src/core/osmo_io.c
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/src/core/osmo_io.c b/src/core/osmo_io.c
index 9d377a8..aaf7bcc 100644
--- a/src/core/osmo_io.c
+++ b/src/core/osmo_io.c
@@ -343,6 +343,7 @@
OSMO_ASSERT(iofd->mode == OSMO_IO_FD_MODE_READ_WRITE);
if (rc <= 0) {
+ talloc_steal(iofd->msgb_alloc.ctx, msg);
iofd->io_ops.read_cb(iofd, rc, msg);
return;
}
@@ -354,6 +355,7 @@
/* It it expected as per API spec that we return the
* return value of read here. The amount of bytes in msg is
* available to the user in msg itself. */
+ talloc_steal(iofd->msgb_alloc.ctx, msg);
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,
@@ -378,15 +380,16 @@
* \param[in] hdr serialized msghdr containing state of completed I/O */
void iofd_handle_recv(struct osmo_io_fd *iofd, struct msgb *msg, int rc, struct iofd_msghdr *hdr)
{
- talloc_steal(iofd->msgb_alloc.ctx, msg);
switch (iofd->mode) {
case OSMO_IO_FD_MODE_READ_WRITE:
iofd_handle_segmented_read(iofd, msg, rc);
break;
case OSMO_IO_FD_MODE_RECVFROM_SENDTO:
+ talloc_steal(iofd->msgb_alloc.ctx, msg);
iofd->io_ops.recvfrom_cb(iofd, rc, msg, &hdr->osa);
break;
case OSMO_IO_FD_MODE_RECVMSG_SENDMSG:
+ talloc_steal(iofd->msgb_alloc.ctx, msg);
iofd->io_ops.recvmsg_cb(iofd, rc, msg, &hdr->hdr);
break;
default:
To view, visit change 40369. To unsubscribe, or for help writing mail filters, visit settings.