Hi!

The current implementation of free_enginetime in lcd_time of the snmplib looks 
like this:

----
void free_enginetime(unsigned char *engineID, size_t engineID_len)
{
    Enginetime      e = NULL;
    int             rval = 0;

    rval = hash_engineID(engineID, engineID_len);
    if (rval < 0)
        return;

    e = etimelist[rval];

    while (e != NULL) {
        etimelist[rval] = e->next;
        SNMP_FREE(e->engineID);
        SNMP_FREE(e);
        e = etimelist[rval];
    }

}
----

so I would say it frees not only the entry of the given engineID but all 
entries that have the same hash. So I do not think that this was the intention 
of what the function should do.

If the function should just remove all entries with the given engineID, I 
suggest something like this:

----
void free_enginetime(unsigned char *engineID, size_t engineID_len)
{
    Enginetime      *pE = NULL;
    int             rval = 0;

    rval = hash_engineID(engineID, engineID_len);
    if (rval < 0)
        return;

    pE = &etimelist[rval];

    while (*pE) {
        Enginetime e = *pE;
        if ((engineID_len == e->engineID_len)
            && !memcmp(e->engineID, engineID, engineID_len)) {
            *pE = e->next;
            SNMP_FREE(e->engineID);
            SNMP_FREE(e);
            continue;
        }
        pE = &(e->next);
    }

}
----
If you're sure, that there is only one entry per engineID, which should be the 
case as far as I understand the rest of lcd_time.c, continue can be replaced 
with break, which saves maybe some extra CPU cycles. Nevertheless, I prefer the 
continue.

So what's your opinion? Am I wrong? Should free_enginetime really be the way it 
is implemented up to now?

Regards,
Walter


#####################################################################################

This message and any attachments are solely for the use of the intended 
recipients. They may contain privileged and/or confidential information or 
other information protected from disclosure. If you are not an intended 
recipient, you are hereby notified that you received this email in error and 
that any review, dissemination, distribution or copying of this email and any 
attachment is strictly prohibited. If you have received this email in error, 
please contact the sender and delete the message and any attachment from your 
system.

Thank You.

#####################################################################################


------------------------------------------------------------------------------
_______________________________________________
Net-snmp-coders mailing list
Net-snmp-coders@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/net-snmp-coders

Reply via email to