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.
This commit is contained in:
Guy Harris 2021-05-23 01:27:11 -07:00
parent 64f3f08702
commit c73ab16bef
1 changed files with 21 additions and 4 deletions

View File

@ -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;
}