From e49a3d714c48f69b90e6f393a6989b6b30ad1282 Mon Sep 17 00:00:00 2001 From: Philipp Maier Date: Wed, 28 Aug 2019 15:09:38 +0200 Subject: [PATCH] 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 --- src/mncc.c | 6 ++++++ 1 file changed, 6 insertions(+) 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; }