ipaccess: e1inp_ipa_bts_rsl_connect: Fix memleak recreating ipa_client_conn

If BTS, using this app, tried to use it in order to re-create the
connection, it would leak the previous strut ipa_client_conn. A similar
fix was already put in place recently for OML, but it was not applied
for RSL.

The leak was spotted by having a BTS connecting fine over OMl but then
failing each time to connect on RSL.

Related: OS#5248
Change-Id: I4ee1ae318b446490783c8b910fca10ba5f72dd5a
This commit is contained in:
Pau Espin 2021-10-11 12:14:36 +02:00
parent d2d28d83a4
commit 92aee5109c
1 changed files with 19 additions and 7 deletions

View File

@ -1005,7 +1005,7 @@ err:
struct ipaccess_line {
bool line_already_initialized;
struct ipa_client_conn *ipa_cli;
struct ipa_client_conn *ipa_cli[NUM_E1_TS]; /* 0=OML, 1+N=TRX_N */
};
static int ipaccess_line_update(struct e1inp_line *line)
@ -1078,10 +1078,10 @@ static int ipaccess_line_update(struct e1inp_line *line)
IPA_TCP_PORT_OML);
/* Drop previous line */
if (il->ipa_cli) {
ipa_client_conn_close(il->ipa_cli);
ipa_client_conn_destroy(il->ipa_cli);
il->ipa_cli = NULL;
if (il->ipa_cli[0]) {
ipa_client_conn_close(il->ipa_cli[0]);
ipa_client_conn_destroy(il->ipa_cli[0]);
il->ipa_cli[0] = NULL;
}
link = ipa_client_conn_create2(tall_ipa_ctx,
@ -1111,7 +1111,7 @@ static int ipaccess_line_update(struct e1inp_line *line)
e1i_ts = e1inp_line_ipa_oml_ts(line);
ipaccess_bts_keepalive_fsm_alloc(e1i_ts, link, "oml_bts_to_bsc");
il->ipa_cli = link;
il->ipa_cli[0] = link;
ret = 0;
break;
}
@ -1137,6 +1137,7 @@ int e1inp_ipa_bts_rsl_connect_n(struct e1inp_line *line,
{
struct ipa_client_conn *rsl_link;
struct e1inp_ts *e1i_ts = e1inp_line_ipa_rsl_ts(line, trx_nr);
struct ipaccess_line *il;
if (E1INP_SIGN_RSL+trx_nr-1 >= NUM_E1_TS) {
LOGP(DLINP, LOGL_ERROR, "cannot create RSL BTS link: "
@ -1144,6 +1145,17 @@ int e1inp_ipa_bts_rsl_connect_n(struct e1inp_line *line,
return -EINVAL;
}
if (!line->driver_data)
line->driver_data = talloc_zero(line, struct ipaccess_line);
il = line->driver_data;
/* Drop previous line */
if (il->ipa_cli[1 + trx_nr]) {
ipa_client_conn_close(il->ipa_cli[1 + trx_nr]);
ipa_client_conn_destroy(il->ipa_cli[1 + trx_nr]);
il->ipa_cli[1 + trx_nr] = NULL;
}
rsl_link = ipa_client_conn_create2(tall_ipa_ctx,
e1inp_line_ipa_rsl_ts(line, trx_nr),
E1INP_SIGN_RSL+trx_nr,
@ -1167,8 +1179,8 @@ int e1inp_ipa_bts_rsl_connect_n(struct e1inp_line *line,
ipa_client_conn_destroy(rsl_link);
return -EIO;
}
ipaccess_bts_keepalive_fsm_alloc(e1i_ts, rsl_link, "rsl_bts_to_bsc");
il->ipa_cli[1 + trx_nr] = rsl_link;
return 0;
}