We've long had double free's in the shutdown code, and one of the causes was
trying to clear up the client args in the callback structures. There is code
that I added in all 3 branches that loops through all the callbacks and clears
a given client arg from any callback that is using it. This is called when a
session is closed, and during the shutdown cleanup.

Unfortunately, a slight coding error reduced the utility of this routine, as
it will only check callbacks for the first callback type. This patch adds a
little debug and initializes the inner loop counter properly so that all
callback types will be cleared.

Without this patch, a subagent which has successfully connected to the master
agent will encounter a double-free during shutdown, and will most likely
crash. Not as critical as a crash during normal operation, but none-the less..

diff -u -p -r5.6.2.2 -r5.6.2.3
--- snmplib/callback.c  21 Apr 2005 14:52:50 -0000      5.6.2.2
+++ snmplib/callback.c  17 Oct 2005 22:24:37 -0000      5.6.2.3
@@ -348,13 +348,14 @@ netsnmp_callback_clear_client_arg(void *
     struct snmp_gen_callback *scp = NULL;
     int rc = 0;

-    for (; i < MAX_CALLBACK_IDS; i++) {
+    for (; i < MAX_CALLBACK_IDS; i++,j=0) {
         for (; j < MAX_CALLBACK_SUBIDS; j++) {
             scp = thecallbacks[i][j];
             while (scp != NULL) {
                 if ((NULL != scp->sc_callback) &&
                     (scp->sc_client_arg != NULL) &&
                     (scp->sc_client_arg == ptr)) {
+                    DEBUGMSGTL(("9:callback", "  clearing %p at [%d,%d]\n",
ptr, i, j)); scp->sc_client_arg = NULL;
                     ++rc;
                 }
@@ -402,6 +403,7 @@ clear_callback(void)
                      */
                     tmp_arg = scp->sc_client_arg;
                     scp->sc_client_arg = NULL;
+                    DEBUGMSGTL(("9:callback", "  freeing %p at [%d,%d]\n",
tmp_arg, i, j)); (void)netsnmp_callback_clear_client_arg(tmp_arg, i, j);
                     free(tmp_arg);
                 }


-- 
Robert Story; NET-SNMP Junkie
Support: <http://www.net-snmp.org/> <irc://irc.freenode.net/#net-snmp>
Archive: <http://sourceforge.net/mailarchive/forum.php?forum=net-snmp-coders>

You are lost in a twisty maze of little standards, all different. 


-------------------------------------------------------
This SF.Net email is sponsored by:
Power Architecture Resource Center: Free content, downloads, discussions,
and more. http://solutions.newsforge.com/ibmarch.tmpl
_______________________________________________
Net-snmp-coders mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/net-snmp-coders

Reply via email to