neels has submitted this change. ( 
https://gerrit.osmocom.org/c/osmo-iuh/+/32531 )

Change subject: asn1tostruct.py: fix leak in error paths of iesDefs
......................................................................

asn1tostruct.py: fix leak in error paths of iesDefs

Related: SYS#6297
Change-Id: I424c4ea2681f5c9a5eec99396502615de5eab841
---
M asn1/utils/asn1tostruct.py
1 file changed, 17 insertions(+), 3 deletions(-)

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




diff --git a/asn1/utils/asn1tostruct.py b/asn1/utils/asn1tostruct.py
index 9b1c1a1..f39f45b 100755
--- a/asn1/utils/asn1tostruct.py
+++ b/asn1/utils/asn1tostruct.py
@@ -328,6 +328,7 @@
     f.write("    int i, decoded = 0;\n")
     if len(iesDefs[key]["ies"]) != 0:
         f.write("    int tempDecoded = 0;\n")
+    f.write("    int rc = -1;\n")

     f.write("    assert(any_p != NULL);\n")
     if len(iesDefs[key]["ies"]) != 0:
@@ -364,7 +365,7 @@
         f.write("                tempDecoded = ANY_to_type_aper(&ie_p->value, 
&asn_DEF_%s, (void**)&%s_p);\n" % (ietypeunderscore, 
lowerFirstCamelWord(ietypesubst)))
         f.write("                if (tempDecoded < 0) {\n")
         f.write("                    %s_DEBUG(\"Decoding of IE %s 
failed\\n\");\n" % (fileprefix.upper(), ienameunderscore))
-        f.write("                    return -1;\n")
+        f.write("                    goto free_and_return_rc;\n")
         f.write("                }\n")
         f.write("                decoded += tempDecoded;\n")
         f.write("                if (asn1_xer_print)\n")
@@ -379,11 +380,14 @@
         f.write("            } break;\n")
     f.write("            default:\n")
     f.write("                %s_DEBUG(\"Unknown protocol IE id (%%d) for 
message %s\\n\", (int)ie_p->id);\n" % (fileprefix.upper(), re.sub('-', '_', 
structName.lower())))
-    f.write("                return -1;\n")
+    f.write("                goto free_and_return_rc;\n")
     f.write("        }\n")
     f.write("    }\n")
+    f.write("    rc = decoded;\n")
+    f.write("\n")
+    f.write("free_and_return_rc:\n")
     f.write("    ASN_STRUCT_FREE(asn_DEF_%s, %s_p);\n" % (asn1cStruct, 
asn1cStructfirstlower))
-    f.write("    return decoded;\n")
+    f.write("    return rc;\n")
     f.write("}\n\n")

 for key in iesDefs:

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

Gerrit-Project: osmo-iuh
Gerrit-Branch: master
Gerrit-Change-Id: I424c4ea2681f5c9a5eec99396502615de5eab841
Gerrit-Change-Number: 32531
Gerrit-PatchSet: 2
Gerrit-Owner: neels <[email protected]>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: fixeria <[email protected]>
Gerrit-Reviewer: msuraev <[email protected]>
Gerrit-Reviewer: neels <[email protected]>
Gerrit-Reviewer: pespin <[email protected]>
Gerrit-MessageType: merged

Reply via email to