I think there is a potential resurce leak in CONTAINER_INSERT that
require a change to the external interface to fix.

Assume a continer with multiple indices.

Assume that all index insert functions returns non-zero, then
CONTAINER_INSERT returns the same non-zero value as the last index
inserter.

Now, assume that only the last index insert function returns non-zero,
then CONTAINER_INSERT will return the same non-zero value as the last
index inserter.

How should a developer know if there are any live references to the
value left when CONTAINER_INSERT returns non-zero?

What does the term 'successful insertion' mean?

I believe that the only reasonable definition of 'successful insertion'
is that all needed insertions succeded, and thus the code for
CONTAINER_INSERT would have to be able to rollback the insertions that
already are done in case of trouble.

But then the problem is that CONTAINER_INSERT must remember the
containers where insertions are done as the result of insert_filter
might change as a result of the insertion and k might be in some index
even if it wasn't inserted by this run.

As a result of those requirements I end up in the following:

int CONTAINER_INSERT_HELPER(netsnmp_container* x, const void* k)
{
  while(x && x->insert_filter(x,k) == 1)
    x = x->next;
  if(x) {
    int rc = x->insert(x,k);
    if(rc)
       snmp_log(LOG_ERR,"error on subcontainer '%s' insert (%d)\n",
                x->container_name ? x->container_name : "", rc);
    else {
      rc = CONTAINER_INSERT_HELPER(x->next, k);
      if(rc)
        x->remove(x,k);
    }
    return rc;
  }
  return 0;
}

int CONTAINER_INSERT(netsnmp_container* x, const void* k)
{
  if(x == NULL)
    return -1;
  while(x->prev)
    x = x->prev;
  return CONTAINER_INSERT_HELPER(x, k);
}

Does anyone have comments to this?

/MF


-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
Net-snmp-coders mailing list
Net-snmp-coders@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/net-snmp-coders

Reply via email to