aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndreas Eversberg <jolly@eversberg.eu>2024-02-15 14:12:01 +0100
committerAndreas Eversberg <jolly@eversberg.eu>2024-03-07 10:28:17 +0100
commite1153bcd376250843a1b13984f458e37a0ed4136 (patch)
tree2927e37ce93b94bd8babae0022e06a3b3c453679
parent1eb221a923d4e25747c80359e90e23ccaebc6140 (diff)
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
-rw-r--r--src/stream_cli.c8
1 files changed, 6 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 @@ static void osmo_stream_cli_close_iofd(struct osmo_stream_cli *cli)
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 @@ int osmo_stream_cli_open(struct osmo_stream_cli *cli)
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 @@ int osmo_stream_cli_open(struct osmo_stream_cli *cli)
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);