aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuy Harris <gharris@sonic.net>2021-05-23 01:27:11 -0700
committerGuy Harris <gharris@sonic.net>2021-05-23 09:54:43 +0000
commitecf1616e35974246b0d9037e135c3df7aad45b9f (patch)
treea828d6069111a601cfeabfa983450fddc4a6444a
parentfaea31d0a1f2ec364c7e7ef25735650c735541c9 (diff)
OID handling: fix a memory leak.
There's a "break" in some code that appears to be copied and pasted from a switch statement; the break would exit the loop (and leak memory allocated within the loop), which does not appear to be the intent, so it may have been copied over incorrectly. Remove it. While we're at it, redo the "constant-time append to the end of a loop" code to be a bit clearer, both to humans reading the code and code analyzers reading the code. (cherry picked from commit c73ab16bef0c97dd67f03fdfa7063958d1712d8b)
-rw-r--r--epan/oids.c25
1 files changed, 21 insertions, 4 deletions
diff --git a/epan/oids.c b/epan/oids.c
index ae065a7338..1023b303a2 100644
--- a/epan/oids.c
+++ b/epan/oids.c
@@ -391,7 +391,7 @@ static inline oid_kind_t smikind(SmiNode* sN, oid_key_t** key_p) {
switch(sN->nodekind) {
case SMI_NODEKIND_ROW: {
SmiElement* sE;
- oid_key_t* kl = NULL;
+ oid_key_t* kl = NULL; /* points to last element in the list of oid_key_t's */
const oid_value_type_t* typedata = NULL;
gboolean implied;
@@ -466,13 +466,30 @@ static inline oid_kind_t smikind(SmiNode* sN, oid_key_t** key_p) {
} else {
k->key_type = OID_KEY_TYPE_WRONG;
k->num_subids = 0;
- break;
}
}
- if (!*key_p) *key_p = k;
- if (kl) kl->next = k;
+ if (!kl) {
+ /*
+ * The list is empty, so set the
+ * pointer to the head of the list
+ * to point to this entry.
+ */
+ *key_p = k;
+ } else {
+ /*
+ * The list is non-empty, and kl
+ * points to its last element.
+ * Make the last element point to
+ * this entry as its successor.
+ */
+ kl->next = k;
+ }
+ /*
+ * This entry is now the last entry in
+ * the list.
+ */
kl = k;
}