laforge has submitted this change. ( https://gerrit.osmocom.org/c/libosmo-netif/+/35979?usp=email )
Change subject: stream_cli: Correctly setup and free osmo_io client instance ......................................................................
stream_cli: Correctly setup and free osmo_io client instance
Free osmo_io instance when calling osmo_stream_cli_close(). Also free osmo_io instance when calling osmo_stream_cli_open() if not freed, to prevent memory leaks.
osmo_iofd_notify_connected() must be called before any registration of read or write, because osmo_io_iouring does not allow this.
Change-Id: I91a6a76b9ff96034a7b333edf87af27490202932 --- M src/stream_cli.c 1 file changed, 22 insertions(+), 2 deletions(-)
Approvals: Jenkins Builder: Verified pespin: Looks good to me, but someone else must approve laforge: Looks good to me, approved
diff --git a/src/stream_cli.c b/src/stream_cli.c index 59f608b..8312faf 100644 --- a/src/stream_cli.c +++ b/src/stream_cli.c @@ -161,7 +161,8 @@ if (!cli->iofd) return;
- osmo_iofd_close(cli->iofd); + osmo_iofd_free(cli->iofd); + cli->iofd = NULL; }
static void osmo_stream_cli_close_ofd(struct osmo_stream_cli *cli) @@ -944,6 +945,8 @@ goto error_close_socket; break; case OSMO_STREAM_MODE_OSMO_IO: + /* Be sure that previous osmo_io instance is freed before creating a new one. */ + osmo_stream_cli_close_iofd(cli); #ifdef HAVE_LIBSCTP if (cli->proto == IPPROTO_SCTP) { cli->iofd = osmo_iofd_setup(cli, fd, cli->name, OSMO_IO_FD_MODE_RECVMSG_SENDMSG, @@ -960,11 +963,12 @@ if (!cli->iofd) goto error_close_socket;
+ osmo_iofd_notify_connected(cli->iofd); + configure_cli_segmentation_cb(cli, cli->segmentation_cb);
if (osmo_iofd_register(cli->iofd, fd) < 0) goto error_close_socket; - osmo_iofd_notify_connected(cli->iofd); break; default: OSMO_ASSERT(false);