diff options
author | Harald Welte <laforge@gnumonks.org> | 2017-03-17 00:15:38 +0100 |
---|---|---|
committer | Harald Welte <laforge@gnumonks.org> | 2017-03-17 12:06:24 +0100 |
commit | a4c1a73250bf174633cefc150d1b641bc48e57ff (patch) | |
tree | ca22bd193e77b02892216609bb3cdae2075fecad /src | |
parent | 781e7b38f87b1a8a4ddf65a040935750aabc2b6e (diff) |
stream: don't crash in _close() when fd is not initialized
We use the magic value '-1' in case the file descriptor is not yet
initialized. If somebody calls osmo_stream_*_close() before this
changes, we used to crash. Let's check for this and avoid a crash.
Also, after close let's change the fd to -1 again to mark the fd
invalidity.
Change-Id: I3aa04999ab01cb7971ee2dad45dfc31ab4142868
Diffstat (limited to 'src')
-rw-r--r-- | src/stream.c | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/src/stream.c b/src/stream.c index d72d800..93de3b7 100644 --- a/src/stream.c +++ b/src/stream.c @@ -101,8 +101,11 @@ static void osmo_stream_cli_reconnect(struct osmo_stream_cli *cli) void osmo_stream_cli_close(struct osmo_stream_cli *cli) { + if (cli->ofd.fd == -1) + return; osmo_fd_unregister(&cli->ofd); close(cli->ofd.fd); + cli->ofd.fd = -1; } static void osmo_stream_cli_read(struct osmo_stream_cli *cli) @@ -506,8 +509,11 @@ int osmo_stream_srv_link_open(struct osmo_stream_srv_link *link) void osmo_stream_srv_link_close(struct osmo_stream_srv_link *link) { + if (link->ofd.fd == -1) + return; osmo_fd_unregister(&link->ofd); close(link->ofd.fd); + link->ofd.fd = -1; } struct osmo_stream_srv { |