summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPhilipp Maier <pmaier@sysmocom.de>2019-08-28 15:09:38 +0200
committerPhilipp Maier <pmaier@sysmocom.de>2019-09-02 14:23:36 +0200
commite49a3d714c48f69b90e6f393a6989b6b30ad1282 (patch)
tree828f0230c22f52b82a412050eeab5bf95225bed8
parent5319d4d979485e5508f545fe68dd54e40a2be7d0 (diff)
mncc: check fd before closing a connection
The function close_connection() closes the fd without marking it as closed. Lets set the fd to -1 and check at the beginning if it is greater than zero. This prevents us from closing an already closed fd again. Related: OS#4159 Change-Id: I9742f31a37296fed15d54cf44c1f65b93abb8c8e
-rw-r--r--src/mncc.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/src/mncc.c b/src/mncc.c
index e23bd6f..f2e2579 100644
--- a/src/mncc.c
+++ b/src/mncc.c
@@ -324,8 +324,12 @@ static void mncc_call_leg_release(struct call_leg *_leg)
/* Close the MNCC connection/socket */
static void close_connection(struct mncc_connection *conn)
{
+ if (conn->fd.fd < 0)
+ return;
+
osmo_fd_unregister(&conn->fd);
close(conn->fd.fd);
+ conn->fd.fd = -1;
osmo_timer_schedule(&conn->reconnect, 5, 0);
conn->state = MNCC_DISCONNECTED;
if (conn->on_disconnect)
@@ -924,6 +928,7 @@ static void mncc_reconnect(void *data)
LOGP(DMNCC, LOGL_ERROR, "Failed to connect(%s). Retrying\n",
conn->app->mncc.path);
conn->state = MNCC_DISCONNECTED;
+ conn->fd.fd = -1;
osmo_timer_schedule(&conn->reconnect, 5, 0);
return;
}
@@ -1022,6 +1027,7 @@ void mncc_connection_init(struct mncc_connection *conn, struct app_config *cfg)
conn->reconnect.data = conn;
conn->fd.cb = mncc_data;
conn->fd.data = conn;
+ conn->fd.fd = -1;
conn->app = cfg;
conn->state = MNCC_DISCONNECTED;
}