This is merely a historical archive of years 2008-2021, before the migration to mailman3.
A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.
Harald Welte gerrit-no-reply at lists.osmocom.org
Review at https://gerrit.osmocom.org/2253
stream/datagram: Ensure reliable close/destroy
* when using osmo_*_destroy(), always call *_close() internally to
make sure we don't free memory holding references to sockets that are
still open
* when closing the socket, always make sure to set the fd to -1 in all
cases, to avoid attempts to avoid later close() on a new file using
the same fd number as the socket closed previously.
Change-Id: I29c37da6e8f5be8ab030e68952a8f92add146821
---
M src/datagram.c
M src/stream.c
2 files changed, 16 insertions(+), 4 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/libosmo-netif refs/changes/53/2253/1
diff --git a/src/datagram.c b/src/datagram.c
index 13f1b5c..d98221f 100644
--- a/src/datagram.c
+++ b/src/datagram.c
@@ -54,8 +54,11 @@
* abstraction and close the socket */
void osmo_dgram_tx_close(struct osmo_dgram_tx *conn)
{
+ if (conn->ofd.fd == -1)
+ return;
osmo_fd_unregister(&conn->ofd);
close(conn->ofd.fd);
+ conn->ofd.fd = -1;
}
static int osmo_dgram_tx_write(struct osmo_dgram_tx *conn)
@@ -173,6 +176,7 @@
* \param[in] conn Datagram Transmitter to destroy */
void osmo_dgram_tx_destroy(struct osmo_dgram_tx *conn)
{
+ osmo_dgram_tx_close(conn);
talloc_free(conn);
}
@@ -198,6 +202,7 @@
conn->ofd.fd = ret;
if (osmo_fd_register(&conn->ofd) < 0) {
close(ret);
+ conn->ofd.fd = -1;
return -EIO;
}
return 0;
@@ -317,10 +322,10 @@
}
/*! \brief Destroy the datagram receiver. Releases Memory.
- * Caller must make sure to osmo_dgram_rx_close() before calling
* \param[in] conn Datagram Receiver */
void osmo_dgram_rx_destroy(struct osmo_dgram_rx *conn)
{
+ osmo_dgram_rx_close(conn);
talloc_free(conn);
}
@@ -345,6 +350,7 @@
conn->ofd.fd = ret;
if (osmo_fd_register(&conn->ofd) < 0) {
close(ret);
+ conn->ofd.fd = -1;
return -EIO;
}
return 0;
@@ -356,8 +362,11 @@
* \param[in] conn Stream Server Link to close */
void osmo_dgram_rx_close(struct osmo_dgram_rx *conn)
{
+ if (conn->ofd.fd == -1)
+ return;
osmo_fd_unregister(&conn->ofd);
close(conn->ofd.fd);
+ conn->ofd.fd = -1;
}
/*
diff --git a/src/stream.c b/src/stream.c
index 7bac1cc..f899a41 100644
--- a/src/stream.c
+++ b/src/stream.c
@@ -367,10 +367,11 @@
cli->read_cb = read_cb;
}
-/*! \brief Destroy a Osmocom stream client
+/*! \brief Destroy a Osmocom stream client (includes close)
* \param[in] cli Stream Client to destroy */
void osmo_stream_cli_destroy(struct osmo_stream_cli *cli)
{
+ osmo_stream_cli_close(cli);
osmo_timer_del(&cli->timer);
talloc_free(cli);
}
@@ -402,6 +403,7 @@
cli->ofd.fd = ret;
if (osmo_fd_register(&cli->ofd) < 0) {
close(ret);
+ cli->ofd.fd = -1;
return -EIO;
}
return 0;
@@ -601,11 +603,11 @@
link->accept_cb = accept_cb;
}
-/*! \brief Destroy the stream server link. Releases Memory.
- * Caller must make sure to osmo_stream_srv_link_close() before calling
+/*! \brief Destroy the stream server link. Closes + Releases Memory.
* \param[in] link Stream Server Link */
void osmo_stream_srv_link_destroy(struct osmo_stream_srv_link *link)
{
+ osmo_stream_srv_link_close(link);
talloc_free(link);
}
@@ -630,6 +632,7 @@
link->ofd.fd = ret;
if (osmo_fd_register(&link->ofd) < 0) {
close(ret);
+ link->ofd.fd = -1;
return -EIO;
}
return 0;
--
To view, visit https://gerrit.osmocom.org/2253
To unsubscribe, visit https://gerrit.osmocom.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I29c37da6e8f5be8ab030e68952a8f92add146821
Gerrit-PatchSet: 1
Gerrit-Project: libosmo-netif
Gerrit-Branch: master
Gerrit-Owner: Harald Welte <laforge at gnumonks.org>