snmp_pdu_free the right object at the right time in snmptool_walk
r310892 was on the right track, but unfortunately it was resolving the problem incorrectly and accidentally leaking memory in the process. - Call snmp_pdu_free on req before calling snmp_pdu_create on it at the bottom of the outer while loop - Call snmp_pdu_free on resp after calling snmpwalk_nextpdu_create in the inner loop MFC after: 12 days X-MFC with: r310729, r310892 Reported by: valgrind
This commit is contained in:
parent
00f6082b98
commit
1b135e4f47
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=310894
@ -422,6 +422,7 @@ snmptool_get(struct snmp_toolinfo *snmptoolctx)
|
|||||||
snmp_pdu_create(&req, GET_PDUTYPE(snmptoolctx));
|
snmp_pdu_create(&req, GET_PDUTYPE(snmptoolctx));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
snmp_pdu_free(&req);
|
||||||
snmp_pdu_free(&resp);
|
snmp_pdu_free(&resp);
|
||||||
|
|
||||||
return (0);
|
return (0);
|
||||||
@ -507,6 +508,7 @@ snmptool_walk(struct snmp_toolinfo *snmptoolctx)
|
|||||||
if (op == SNMP_PDU_GETBULK)
|
if (op == SNMP_PDU_GETBULK)
|
||||||
snmpget_fix_getbulk(&req, GET_MAXREP(snmptoolctx),
|
snmpget_fix_getbulk(&req, GET_MAXREP(snmptoolctx),
|
||||||
GET_NONREP(snmptoolctx));
|
GET_NONREP(snmptoolctx));
|
||||||
|
snmp_pdu_free(&resp);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Just in case our root was a leaf. */
|
/* Just in case our root was a leaf. */
|
||||||
@ -517,6 +519,7 @@ snmptool_walk(struct snmp_toolinfo *snmptoolctx)
|
|||||||
snmp_output_err_resp(snmptoolctx, &resp);
|
snmp_output_err_resp(snmptoolctx, &resp);
|
||||||
else
|
else
|
||||||
snmp_output_resp(snmptoolctx, &(resp), NULL);
|
snmp_output_resp(snmptoolctx, &(resp), NULL);
|
||||||
|
snmp_pdu_free(&resp);
|
||||||
} else
|
} else
|
||||||
warn("Snmp dialog");
|
warn("Snmp dialog");
|
||||||
}
|
}
|
||||||
@ -526,11 +529,13 @@ snmptool_walk(struct snmp_toolinfo *snmptoolctx)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
snmp_pdu_free(&resp);
|
snmp_pdu_free(&req);
|
||||||
|
|
||||||
snmp_pdu_create(&req, op);
|
snmp_pdu_create(&req, op);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
snmp_pdu_free(&req);
|
||||||
|
snmp_pdu_free(&resp);
|
||||||
|
|
||||||
if (rc == 0)
|
if (rc == 0)
|
||||||
return (0);
|
return (0);
|
||||||
else
|
else
|
||||||
|
Loading…
Reference in New Issue
Block a user