diff --git a/usr.sbin/bsnmpd/tools/bsnmptools/bsnmpget.c b/usr.sbin/bsnmpd/tools/bsnmptools/bsnmpget.c index 0f74eb2ae768..752ddc0f0399 100644 --- a/usr.sbin/bsnmpd/tools/bsnmptools/bsnmpget.c +++ b/usr.sbin/bsnmpd/tools/bsnmptools/bsnmpget.c @@ -400,13 +400,16 @@ snmptool_get(struct snmp_toolinfo *snmptoolctx) if (snmp_parse_resp(&resp, &req) >= 0) { snmp_output_resp(snmptoolctx, &resp, NULL); + snmp_pdu_free(&resp); break; } snmp_output_err_resp(snmptoolctx, &resp); if (GET_PDUTYPE(snmptoolctx) == SNMP_PDU_GETBULK || - !ISSET_RETRY(snmptoolctx)) + !ISSET_RETRY(snmptoolctx)) { + snmp_pdu_free(&resp); break; + } /* * Loop through the object list and set object->error to the @@ -414,8 +417,10 @@ snmptool_get(struct snmp_toolinfo *snmptoolctx) */ if (snmp_object_seterror(snmptoolctx, &(resp.bindings[resp.error_index - 1]), - resp.error_status) <= 0) + resp.error_status) <= 0) { + snmp_pdu_free(&resp); break; + } fprintf(stderr, "Retrying...\n"); snmp_pdu_free(&resp); @@ -423,7 +428,6 @@ snmptool_get(struct snmp_toolinfo *snmptoolctx) } snmp_pdu_free(&req); - snmp_pdu_free(&resp); return (0); } @@ -500,8 +504,10 @@ snmptool_walk(struct snmp_toolinfo *snmptoolctx) outputs += rc; - if ((u_int)rc < resp.nbindings) + if ((u_int)rc < resp.nbindings) { + snmp_pdu_free(&resp); break; + } snmpwalk_nextpdu_create(op, &(resp.bindings[resp.nbindings - 1].var), &req); @@ -515,10 +521,11 @@ snmptool_walk(struct snmp_toolinfo *snmptoolctx) if (outputs == 0) { snmpwalk_nextpdu_create(SNMP_PDU_GET, &root, &req); if (snmp_dialog(&req, &resp) == SNMP_CODE_OK) { - if (snmp_parse_resp(&resp,&req) < 0) + if (snmp_parse_resp(&resp, &req) < 0) snmp_output_err_resp(snmptoolctx, &resp); else - snmp_output_resp(snmptoolctx, &(resp), NULL); + snmp_output_resp(snmptoolctx, &resp, + NULL); snmp_pdu_free(&resp); } else warn("Snmp dialog"); @@ -534,7 +541,6 @@ snmptool_walk(struct snmp_toolinfo *snmptoolctx) } snmp_pdu_free(&req); - snmp_pdu_free(&resp); if (rc == 0) return (0); @@ -1094,25 +1100,29 @@ snmptool_set(struct snmp_toolinfo *snmptoolctx) if (snmp_pdu_check(&req, &resp) > 0) { if (GET_OUTPUT(snmptoolctx) != OUTPUT_QUIET) snmp_output_resp(snmptoolctx, &resp, NULL); + snmp_pdu_free(&resp); break; } snmp_output_err_resp(snmptoolctx, &resp); - if (!ISSET_RETRY(snmptoolctx)) + if (!ISSET_RETRY(snmptoolctx)) { + snmp_pdu_free(&resp); break; + } if (snmp_object_seterror(snmptoolctx, &(resp.bindings[resp.error_index - 1]), - resp.error_status) <= 0) + resp.error_status) <= 0) { + snmp_pdu_free(&resp); break; + } fprintf(stderr, "Retrying...\n"); snmp_pdu_free(&req); - snmp_pdu_free(&resp); snmp_pdu_create(&req, SNMP_PDU_SET); } - snmp_pdu_free(&resp); + snmp_pdu_free(&req); return (0); }