smidump generates netsnmp wrappers that appear to contain a small memory
leak if snmp_open() fails. For example...
> int powernet_mib_mgr_get_upsPhaseResetValues(struct snmp_session *s, upsPhaseResetValues_t **upsPhaseResetValues)
> {
> struct snmp_session *peer;
> struct snmp_pdu *request, *response;
> struct variable_list *vars;
> int status;
>
> request = snmp_pdu_create(SNMP_MSG_GETNEXT);
request is allocated...
> snmp_add_null_var(request, upsPhaseResetMaxMinValues, sizeof(upsPhaseResetMaxMinValues)/sizeof(oid));
>
> peer = snmp_open(s);
> if (!peer) {
> return -1;
...and here we potentially return without freeing it.
> }
>
> status = snmp_synch_response(peer, request, &response);
snmp_synch_response() frees request in all cases, so there are no leaks
after this point.
> if (status != STAT_SUCCESS) {
> if (response) snmp_free_pdu(response);
> snmp_close(peer);
> return -2;
> }
>
> ...
My knowledge of netsnmp is limited, but I believe the analysis above
is correct. Below is a small patch to solve the problem.
--Adam
--- libsmi-0.4.5/tools/dump-netsnmp.c 2005-11-25 04:13:58.000000000 -0500
+++ libsmi-0.4.5/tools/dump-netsnmp.new.c 2006-05-30 18:30:36.000000000 -0400
@@ -1149,6 +1149,7 @@
"\n"
" peer = snmp_open(s);\n"
" if (!peer) {\n"
+ " snmp_free_pdu(request);\n"
" return -1;\n"
" }\n"
"\n"