aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHarald Welte <laforge@osmocom.org>2021-03-04 13:14:05 +0100
committerHarald Welte <laforge@osmocom.org>2021-03-23 15:27:21 +0100
commit7035a6621ae57889f33a87bbbe9ea7cfc13eb9e3 (patch)
tree6961add9c3e427b9323cce14e61285d87653d323
parent18fd648b80a1d882ba440867a681a1b68c8f9406 (diff)
gprs_ns2_sns: Fix memory leak when creating ip[46]_local arrays
Prior to this patch, we would unconditionally allocate new memory for the local SNS IP endpoints. This results in a memory leak on every SNS-SIZE procedure. Let's move to talloc_realloc() which recycles any previously allocated memory. Change-Id: I12cb670e087c6d6190f3f5bf8483ea62008ae06f
-rw-r--r--src/gb/gprs_ns2_sns.c5
1 files changed, 2 insertions, 3 deletions
diff --git a/src/gb/gprs_ns2_sns.c b/src/gb/gprs_ns2_sns.c
index 51e4e9e3..596d1200 100644
--- a/src/gb/gprs_ns2_sns.c
+++ b/src/gb/gprs_ns2_sns.c
@@ -806,7 +806,7 @@ static void ns2_sns_compute_local_ep_from_binds(struct osmo_fsm_inst *fi)
switch (gss->ip) {
case IPv4:
- ip4_elems = talloc_zero_size(fi, sizeof(struct gprs_ns_ie_ip4_elem) * count);
+ ip4_elems = talloc_realloc(fi, gss->ip4_local, struct gprs_ns_ie_ip4_elem, count);
if (!ip4_elems)
return;
@@ -841,7 +841,7 @@ static void ns2_sns_compute_local_ep_from_binds(struct osmo_fsm_inst *fi)
break;
case IPv6:
/* IPv6 */
- ip6_elems = talloc_zero_size(fi, sizeof(struct gprs_ns_ie_ip6_elem) * count);
+ ip6_elems = talloc_realloc(fi, gss->ip6_local, struct gprs_ns_ie_ip6_elem, count);
if (!ip6_elems)
return;
@@ -920,7 +920,6 @@ static void ns2_sns_st_bss_size_onenter(struct osmo_fsm_inst *fi, uint32_t old_s
gss->sns_nsvc->sns_only = true;
}
-
if (gss->num_max_ip4_remote > 0)
ns2_tx_sns_size(gss->sns_nsvc, true, gss->num_max_nsvcs, gss->num_ip4_local, -1);
else