se_add_pair_to_slist is declared as
int se_add_pair_to_slist(char* list, char* label, int value)
I will use 'label' and 'value' below to refer to the arguments.
In snmp_api.c, line 776 and 777 says:
se_add_pair_to_slist("asntypes", strdup("uinteger"), ASN_GAUGE);
se_add_pair_to_slist("asntypes", strdup("unsigned"), ASN_UNSIGNED); /* RFC 1902
- same as GAUGE */
The second call to se_add_pair_to_slist will always return
SE_ALREADY_THERE since, as the comment mentions, ASN_GAUGE equals
ASN_UNSIGNED, and se_add_pair_to_slist enforces that the values are
unique.
The effect of this is that every caller of init_snmp leaks 9 bytes of
memory, so this raises a question:
* Should se_add_pair_to_slist etc. take ownership of the inserted string
always, only on success or never?
Right now it seems to be only on success.
The point of never is that the strdup can be skipped in that case.
Now, if one looks at the sole use of this enum in the agent then that is
in agent/mibgroup/utilities/override.c and there the lookup is done from
label to value, so there it would make sense to allow multiple values
but to make sure that the labels are unique.
This in turn raises more questions:
* Why is the enum initialized in the library when only a mibgroup object
uses it?
* Is an enum like this the right data structure in this case?
And then comes the final problem, what to do:
1. Should the initialization o this enum be moved to
agent/mibgroup/utilities/override.c
2. Should we continue using a se_-enum given that the use case calls for
somethig else?
3. Should we remove snmp_api.c:777?
4. Should the ownership handling in se_add_pair* change? (API change)
/MF
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Net-snmp-coders mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/net-snmp-coders