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
This commit is contained in:
Philipp Maier 2019-08-28 15:09:38 +02:00
parent 5319d4d979
commit e49a3d714c
1 changed files with 6 additions and 0 deletions

View File

@ -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;
}