diff options
author | Stefan Sperling <ssperling@sysmocom.de> | 2018-11-09 15:04:12 +0100 |
---|---|---|
committer | Stefan Sperling <ssperling@sysmocom.de> | 2018-11-09 15:33:19 +0100 |
commit | a555a1fca28f6ba1c5c877bb3d94f2b77396ed64 (patch) | |
tree | fb7997fad601aa7dd92077351f0e6c2eb6a00d1e | |
parent | 7028d7387efc2e0fbac403de075c4c9c2d310f80 (diff) |
detect freed connections in osmo_stream_srv_read()
While we are processing a read event, the connection's
callback might free the connection. Check for this and don't
attempt to process further events on an already freed connection.
Change-Id: I0a9c7d8e3263c73440f7084dbb1792a4ca5038f0
Related: OS#3685
Depends: g#11704 (for libosmo-sccp)
-rw-r--r-- | src/stream.c | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/src/stream.c b/src/stream.c index 6eb2313..4548414 100644 --- a/src/stream.c +++ b/src/stream.c @@ -784,19 +784,21 @@ struct osmo_stream_srv { int flags; }; -static void osmo_stream_srv_read(struct osmo_stream_srv *conn) +static int osmo_stream_srv_read(struct osmo_stream_srv *conn) { + int rc = 0; + LOGP(DLINP, LOGL_DEBUG, "message received\n"); if (conn->flags & OSMO_STREAM_SRV_F_FLUSH_DESTROY) { LOGP(DLINP, LOGL_DEBUG, "Connection is being flushed and closed; ignoring received message\n"); - return; + return 0; } if (conn->cb) - conn->cb(conn); + rc = conn->cb(conn); - return; + return rc; } static void osmo_stream_srv_write(struct osmo_stream_srv *conn) @@ -845,14 +847,15 @@ static void osmo_stream_srv_write(struct osmo_stream_srv *conn) static int osmo_stream_srv_cb(struct osmo_fd *ofd, unsigned int what) { struct osmo_stream_srv *conn = ofd->data; + int rc = 0; LOGP(DLINP, LOGL_DEBUG, "connected read/write\n"); if (what & BSC_FD_READ) - osmo_stream_srv_read(conn); - if (what & BSC_FD_WRITE) + rc = osmo_stream_srv_read(conn); + if (rc != -EBADF && (what & BSC_FD_WRITE)) osmo_stream_srv_write(conn); - return 0; + return rc; } /*! \brief Create a Stream Server inside the specified link |