From 192a8595d0161cf1a095c7386c153c99ed2c1bc3 Mon Sep 17 00:00:00 2001 From: Vadim Yanitskiy Date: Thu, 17 Jan 2019 10:53:10 +0700 Subject: [PATCH] trxcon/trx_if.c: check if trx_fsm allocation failed Change-Id: I31c9f2a651182b258d0a4d4504365b778529715a --- src/host/trxcon/trx_if.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/host/trxcon/trx_if.c b/src/host/trxcon/trx_if.c index 91b87a2ae..bff73ccf7 100644 --- a/src/host/trxcon/trx_if.c +++ b/src/host/trxcon/trx_if.c @@ -645,6 +645,16 @@ int trx_if_open(struct trx_instance **trx, const char *local_host, return -ENOMEM; } + /* Allocate a new dedicated state machine */ + trx_new->fsm = osmo_fsm_inst_alloc(&trx_fsm, trx_new, + NULL, LOGL_DEBUG, "trx_interface"); + if (trx_new->fsm == NULL) { + LOGP(DTRX, LOGL_ERROR, "Failed to allocate an instance " + "of FSM '%s'\n", trx_fsm.name); + talloc_free(trx_new); + return -ENOMEM; + } + /* Initialize CTRL queue */ INIT_LLIST_HEAD(&trx_new->trx_ctrl_list); @@ -659,16 +669,13 @@ int trx_if_open(struct trx_instance **trx, const char *local_host, if (rc < 0) goto error; - /* Allocate a new dedicated state machine */ - trx_new->fsm = osmo_fsm_inst_alloc(&trx_fsm, trx_new, - NULL, LOGL_DEBUG, "trx_interface"); - *trx = trx_new; return 0; error: LOGP(DTRX, LOGL_ERROR, "Couldn't establish UDP connection\n"); + osmo_fsm_inst_free(trx_new->fsm); talloc_free(trx_new); return rc; }