pespin has uploaded this change for review. ( 
https://gerrit.osmocom.org/c/libosmocore/+/35347?usp=email )


Change subject: ipa_ccm_tlv_to_unitdata(): free previous string if present 
before allocating new one
......................................................................

ipa_ccm_tlv_to_unitdata(): free previous string if present before allocating 
new one

Change-Id: I66cbd900676875145810ad1d5c07e719311852fb
---
M src/gsm/ipa.c
1 file changed, 28 insertions(+), 12 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/47/35347/1

diff --git a/src/gsm/ipa.c b/src/gsm/ipa.c
index cd95c6b..40d7098 100644
--- a/src/gsm/ipa.c
+++ b/src/gsm/ipa.c
@@ -267,34 +267,41 @@
        return 0;
 }

+/*! Fill ud struct from tp structure.
+ *  \param[in] ud ipaccess_unit to fill
+ *  \param[in] tp the decoded TLV structure from eg. ID_RESP message
+ *  \returns zero on success, negative on error
+ *
+ * This function expects parameter ud's fields to be initialized to zero if 
not yet set.
+ **/
 int ipa_ccm_tlv_to_unitdata(struct ipaccess_unit *ud,
                             const struct tlv_parsed *tp)
 {
        int rc = 0;

        if (TLVP_PRES_LEN(tp, IPAC_IDTAG_SERNR, 1))
-               ud->serno = talloc_strdup(ud, (char *)
-                                       TLVP_VAL(tp, IPAC_IDTAG_SERNR));
+               osmo_talloc_replace_string(ud, &ud->serno,
+                                          (char *)TLVP_VAL(tp, 
IPAC_IDTAG_SERNR));

        if (TLVP_PRES_LEN(tp, IPAC_IDTAG_UNITNAME, 1))
-               ud->unit_name = talloc_strdup(ud, (char *)
-                                       TLVP_VAL(tp, IPAC_IDTAG_UNITNAME));
+               osmo_talloc_replace_string(ud, &ud->unit_name,
+                                          (char *)TLVP_VAL(tp, 
IPAC_IDTAG_UNITNAME));

        if (TLVP_PRES_LEN(tp, IPAC_IDTAG_LOCATION1, 1))
-               ud->location1 = talloc_strdup(ud, (char *)
-                                       TLVP_VAL(tp, IPAC_IDTAG_LOCATION1));
+               osmo_talloc_replace_string(ud, &ud->location1,
+                                          (char *)TLVP_VAL(tp, 
IPAC_IDTAG_LOCATION1));

        if (TLVP_PRES_LEN(tp, IPAC_IDTAG_LOCATION2, 1))
-               ud->location2 = talloc_strdup(ud, (char *)
-                                       TLVP_VAL(tp, IPAC_IDTAG_LOCATION2));
+               osmo_talloc_replace_string(ud, &ud->location2,
+                                          (char *)TLVP_VAL(tp, 
IPAC_IDTAG_LOCATION2));

        if (TLVP_PRES_LEN(tp, IPAC_IDTAG_EQUIPVERS, 1))
-               ud->equipvers = talloc_strdup(ud, (char *)
-                                       TLVP_VAL(tp, IPAC_IDTAG_EQUIPVERS));
+               osmo_talloc_replace_string(ud, &ud->equipvers,
+                                          (char *)TLVP_VAL(tp, 
IPAC_IDTAG_EQUIPVERS));

        if (TLVP_PRES_LEN(tp, IPAC_IDTAG_SWVERSION, 1))
-               ud->swversion = talloc_strdup(ud, (char *)
-                                       TLVP_VAL(tp, IPAC_IDTAG_SWVERSION));
+               osmo_talloc_replace_string(ud, &ud->swversion,
+                                          (char *)TLVP_VAL(tp, 
IPAC_IDTAG_SWVERSION));

        if (TLVP_PRES_LEN(tp, IPAC_IDTAG_MACADDR, 17)) {
                rc = osmo_macaddr_parse(ud->mac_addr, (char *)

--
To view, visit https://gerrit.osmocom.org/c/libosmocore/+/35347?usp=email
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings

Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: I66cbd900676875145810ad1d5c07e719311852fb
Gerrit-Change-Number: 35347
Gerrit-PatchSet: 1
Gerrit-Owner: pespin <pes...@sysmocom.de>
Gerrit-MessageType: newchange

Reply via email to