Change in libosmocore[master]: gprs_ns2_sns: Fix memory leak when creating ip[46]_local arrays

laforge gerrit-no-reply at lists.osmocom.org
Mon Mar 29 11:35:32 UTC 2021


laforge has submitted this change. ( https://gerrit.osmocom.org/c/libosmocore/+/23417 )

Change subject: gprs_ns2_sns: Fix memory leak when creating ip[46]_local arrays
......................................................................

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
---
M src/gb/gprs_ns2_sns.c
1 file changed, 2 insertions(+), 3 deletions(-)

Approvals:
  Jenkins Builder: Verified
  pespin: Looks good to me, but someone else must approve
  daniel: Looks good to me, approved



diff --git a/src/gb/gprs_ns2_sns.c b/src/gb/gprs_ns2_sns.c
index b07f010..144ab21 100644
--- a/src/gb/gprs_ns2_sns.c
+++ b/src/gb/gprs_ns2_sns.c
@@ -811,7 +811,7 @@
 
 	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;
 
@@ -846,7 +846,7 @@
 		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;
 
@@ -925,7 +925,6 @@
 		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

-- 
To view, visit https://gerrit.osmocom.org/c/libosmocore/+/23417
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: I12cb670e087c6d6190f3f5bf8483ea62008ae06f
Gerrit-Change-Number: 23417
Gerrit-PatchSet: 7
Gerrit-Owner: laforge <laforge at osmocom.org>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: daniel <dwillmann at sysmocom.de>
Gerrit-Reviewer: laforge <laforge at osmocom.org>
Gerrit-Reviewer: pespin <pespin at sysmocom.de>
Gerrit-MessageType: merged
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20210329/044c4013/attachment.htm>


More information about the gerrit-log mailing list