laforge submitted this change.

View Change


Approvals: Jenkins Builder: Verified pespin: Looks good to me, but someone else must approve laforge: Looks good to me, approved
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(-)

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);

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

Gerrit-Project: libosmo-netif
Gerrit-Branch: master
Gerrit-Change-Id: I91a6a76b9ff96034a7b333edf87af27490202932
Gerrit-Change-Number: 35979
Gerrit-PatchSet: 8
Gerrit-Owner: jolly <andreas@eversberg.eu>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: daniel <dwillmann@sysmocom.de>
Gerrit-Reviewer: dexter <pmaier@sysmocom.de>
Gerrit-Reviewer: laforge <laforge@osmocom.org>
Gerrit-Reviewer: pespin <pespin@sysmocom.de>
Gerrit-MessageType: merged