From 413b17eecd6af8e8247501805b5a366b709828bf Mon Sep 17 00:00:00 2001
From: Bart Van Assche <bvanassche@acm.org>
Date: Mon, 9 Aug 2021 14:07:20 -0700
Subject: [PATCH] libsnmp: Fix the getoid() error path

Fixes: d0277ca1ccd6 ("libsnmp: Fix a memory leak in a MIB parser error path")
---
 snmplib/parse.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/snmplib/parse.c b/snmplib/parse.c
index 5eb675b..19ccc0f 100644
--- a/snmplib/parse.c
+++ b/snmplib/parse.c
@@ -1929,11 +1929,12 @@ getoid(FILE * fp, struct subid_s *id_arg, int length)
         type = get_token(fp, token, MAXTOKEN);
     }
     print_error("Too long OID", token, type);
+    --count;
 
 free_labels:
-    for (i = 0; i < count; i++) {
-        free(id[i].label);
-        id[i].label = NULL;
+    for (i = 0; i <= count; i++) {
+        free(id_arg[i].label);
+        id_arg[i].label = NULL;
     }
 
     return 0;
-- 
1.8.3.1

