diff options
author | Harald Welte <laforge@gnumonks.org> | 2017-04-08 22:17:19 +0200 |
---|---|---|
committer | Harald Welte <laforge@gnumonks.org> | 2017-04-10 06:52:59 +0000 |
commit | 7cee4b67e90aeb260bde11ee7f299e507c94bc10 (patch) | |
tree | 8a2b91a982de8c727116e406b2c1b2866c1c2c4e /src/stream.c | |
parent | 0bacc71fc208e5cdf0727de027438b8e901ff666 (diff) |
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
Diffstat (limited to 'src/stream.c')
-rw-r--r-- | src/stream.c | 9 |
1 files changed, 6 insertions, 3 deletions
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 @@ osmo_stream_cli_set_read_cb(struct osmo_stream_cli *cli, 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 @@ int osmo_stream_cli_open2(struct osmo_stream_cli *cli, int reconnect) 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 @@ void osmo_stream_srv_link_set_accept_cb(struct osmo_stream_srv_link *link, 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 @@ int osmo_stream_srv_link_open(struct osmo_stream_srv_link *link) link->ofd.fd = ret; if (osmo_fd_register(&link->ofd) < 0) { close(ret); + link->ofd.fd = -1; return -EIO; } return 0; |