]> git.ipfire.org Git - thirdparty/ntp.git/commitdiff
Add extra heap-checking calls to atexit-invoked routines
authorDave Hart <hart@ntp.org>
Sun, 16 Aug 2009 17:41:19 +0000 (17:41 +0000)
committerDave Hart <hart@ntp.org>
Sun, 16 Aug 2009 17:41:19 +0000 (17:41 +0000)
dump -4 and -6 switches to server/peer
use %g printf format instead of %f to trim uninformative zeros
switch enable/disable dumper to correct oddball identifiers
Do not free in-use receive buffers at exit to avoid race for now

bk: 4a8844bftr6tgRFDxzFLuN4PKrG0jA

ntpd/ntp_config.c
ntpd/ntp_util.c
ports/winnt/ntpd/ntp_iocompletionport.c

index 8617475a5e72242e77a38c2f6e4c2f0112e0bf62..0bb00861bfbbca2d5825ec3bfb6388eea9809386 100644 (file)
@@ -374,6 +374,10 @@ free_all_config_trees(void)
 static void
 free_config_tree(struct config_tree *ptree)
 {
+#if defined(_MSC_VER) && defined (_DEBUG)
+       _CrtCheckMemory();
+#endif
+
        if (ptree->source.value.s != NULL)
                free(ptree->source.value.s);
 
@@ -406,6 +410,10 @@ free_config_tree(struct config_tree *ptree)
        free_auth_node(ptree);
 
        free(ptree);
+
+#if defined(_MSC_VER) && defined (_DEBUG)
+       _CrtCheckMemory();
+#endif
 }
 #endif /* DEBUG */
 
@@ -494,27 +502,45 @@ dump_config_tree(
                default:
                        fprintf(df, "# dump error:\n"
                                "# unknown peer token %d for:\n"
-                               "peer %s", peers->host_mode,
-                               addr->address);
+                               "peer ", peers->host_mode);
                        break;
 
                case T_Peer:
-                       fprintf(df, "peer %s", addr->address);
+                       fprintf(df, "peer");
                        break;
 
                case T_Server:
-                       fprintf(df, "server %s", addr->address);
+                       fprintf(df, "server");
                        break;
 
                case T_Broadcast:
-                       fprintf(df, "broadcast %s", addr->address);
+                       fprintf(df, "broadcast");
                        break;
 
                case T_Manycastclient:
-                       fprintf(df, "manycastclient %s", addr->address);
+                       fprintf(df, "manycastclient");
                        break;
                }
 
+               if (addr->type != AF_UNSPEC) {
+                       switch (addr->type) {
+
+                       default:
+                               fprintf(df, "# dump error:\n"
+                                       "# unknown peer family %d for:\n"
+                                       "peer", addr->type);
+                               break;
+
+                       case AF_INET:
+                               fprintf(df, " -4");
+                               break;
+
+                       case AF_INET6:
+                               fprintf(df, " -6");
+                               break;
+                       }
+               }
+               fprintf(df, " %s", addr->address);
                
                for (atrv = queue_head(peers->options); 
                     atrv != NULL;
@@ -586,7 +612,7 @@ dump_config_tree(
                                break;
 
                        case T_Bias:
-                               fprintf(df, " bias %f", atrv->value.d);
+                               fprintf(df, " bias %g", atrv->value.d);
                                break;
 
                        case T_Key:
@@ -650,11 +676,11 @@ dump_config_tree(
                                                        break;
 
                                                        case CLK_HAVETIME1:
-                                                       fprintf(df, " time1 %f", atrv->value.d);
+                                                       fprintf(df, " time1 %g", atrv->value.d);
                                                        break;
                                        
                                                        case CLK_HAVETIME2:
-                                                       fprintf(df, " time2 %f", atrv->value.d);
+                                                       fprintf(df, " time2 %g", atrv->value.d);
                                                        break;
                        
                                                        case CLK_HAVEVAL1:
@@ -774,23 +800,23 @@ dump_config_tree(
                                break;
 
                        case PROTO_ORPHAN:
-                               fprintf(df, " orphan %d", (int) atrv->value.d);
+                               fprintf(df, " orphan %d", (int)atrv->value.d);
                                break;
 
                        case PROTO_MINDISP:
-                               fprintf(df, " mindist %f", atrv->value.d);
+                               fprintf(df, " mindist %g", atrv->value.d);
                                break;
                                
                        case PROTO_MAXDIST:
-                               fprintf(df, " maxdist %f", atrv->value.d);
+                               fprintf(df, " maxdist %g", atrv->value.d);
                                break;
 
                        case PROTO_MINCLOCK:
-                               fprintf(df, " minclock %f", atrv->value.d);
+                               fprintf(df, " minclock %d", (int)atrv->value.d);
                                break;
 
                        case PROTO_MAXCLOCK:
-                               fprintf(df, " maxclock %f", atrv->value.d);
+                               fprintf(df, " maxclock %d", (int)atrv->value.d);
                                break;
 
                        case PROTO_MINSANE:
@@ -1060,74 +1086,43 @@ dump_config_tree(
 
                        fprintf(df, "enable");
 
-                       switch (atrv->attr) {
+                       switch (atrv->value.i) {
                        default:
                                fprintf(df, "\n# dump error:\n"
                                        "# unknown enable token %d\n"
-                                       "enable", atrv->attr);
-                               break;
-
-                               case T_Autokey: 
-                               fprintf(df, " autokey");        
-                               break;
-
-                               case T_Bias: 
-                               fprintf(df, " bias");
-                               break;
-
-                               case T_Burst: 
-                               fprintf(df, " burst");
-                               break;
-
-                               case T_Iburst: 
-                               fprintf(df, " iburst");
-                               break;
-
-                               case T_Key: 
-                               fprintf(df, " key");
-                               break;
-
-                               case T_Maxpoll: 
-                               fprintf(df, " maxpoll");
-                               break;
-
-                               case T_Minpoll: 
-                               fprintf(df, " minpoll");
+                                       "enable", atrv->value.i);
                                break;
 
-                               case T_Mode
-                               fprintf(df, " mode");
+                               case PROTO_AUTHENTICATE
+                               fprintf(df, " auth");   
                                break;
 
-                               case T_Noselect
-                               fprintf(df, " noselect");
+                               case PROTO_BROADCLIENT
+                               fprintf(df, " bclient");
                                break;
 
-                               case T_Preempt
-                               fprintf(df, " preempt");
+                               case PROTO_CAL
+                               fprintf(df, " calibrate");
                                break;
 
-                               case T_True
-                               fprintf(df, " true");
+                               case PROTO_KERNEL
+                               fprintf(df, " kernel");
                                break;
 
-                               case T_Prefer
-                               fprintf(df, " prefer");
+                               case PROTO_MONITOR
+                               fprintf(df, " monitor");
                                break;
 
-                               case T_Ttl
-                               fprintf(df, " ttl");
+                               case PROTO_NTP
+                               fprintf(df, " ntp");
                                break;
 
-                               case T_Version: 
-                               fprintf(df, " version");
-                               break;
-
-                               case T_Xleave: 
-                               fprintf(df, " xleave");
+                               case PROTO_FILEGEN: 
+                               fprintf(df, " stats");
                                break;
                        }
                }
+               fprintf(df, "\n");
        }
 
        list_ptr = queue_head(ptree->disable_opts);
@@ -1140,75 +1135,43 @@ dump_config_tree(
 
                        atrv = (struct attr_val *) list_ptr;
 
-                       switch (atrv->attr) {
+                       switch (atrv->value.i) {
                        default:
                                fprintf(df, "\n# dump error:\n"
                                        "# unknown disable token %d\n"
-                                       "disable", atrv->attr);
-                               break;
-
-                               case T_Autokey: 
-                               fprintf(df, " autokey");        
-                               break;
-
-                               case T_Bias: 
-                               fprintf(df, " bias");
-                               break;
-
-                               case T_Burst: 
-                               fprintf(df, " burst");
+                                       "disable", atrv->value.i);
                                break;
 
-                               case T_Iburst
-                               fprintf(df, " iburst");
+                               case PROTO_AUTHENTICATE
+                               fprintf(df, " auth");   
                                break;
 
-                               case T_Key
-                               fprintf(df, " key");
+                               case PROTO_BROADCLIENT
+                               fprintf(df, " bclient");
                                break;
 
-                               case T_Maxpoll
-                               fprintf(df, " maxpoll");
+                               case PROTO_CAL
+                               fprintf(df, " calibrate");
                                break;
 
-                               case T_Minpoll
-                               fprintf(df, " minpoll");
+                               case PROTO_KERNEL
+                               fprintf(df, " kernel");
                                break;
 
-                               case T_Mode
-                               fprintf(df, " mode");
+                               case PROTO_MONITOR
+                               fprintf(df, " monitor");
                                break;
 
-                               case T_Noselect
-                               fprintf(df, " noselect");
+                               case PROTO_NTP
+                               fprintf(df, " ntp");
                                break;
 
-                               case T_Preempt: 
-                               fprintf(df, " preempt");
-                               break;
-
-                               case T_True: 
-                               fprintf(df, " true");
-                               break;
-
-                               case T_Prefer: 
-                               fprintf(df, " prefer");
-                               break;
-
-                               case T_Ttl: 
-                               fprintf(df, " ttl");
-                               break;
-
-                               case T_Version: 
-                               fprintf(df, " version");
-                               break;
-
-                               case T_Xleave: 
-                               fprintf(df, " xleave");
+                               case PROTO_FILEGEN: 
+                               fprintf(df, " stats");
                                break;
                        }
                }
-
+               fprintf(df, "\n");
        }
 
        list_ptr = queue_head(ptree->tinker);
@@ -1408,7 +1371,7 @@ dump_config_tree(
                                break;
 
                                case T_Broadcastdelay:
-                               fprintf(df, "broadcastdelay %f\n", atrv->value.d);
+                               fprintf(df, "broadcastdelay %g\n", atrv->value.d);
                                break;
                                
                                case T_Calldelay:
@@ -1416,7 +1379,7 @@ dump_config_tree(
                                break;
 
                                case T_Tick:
-                               fprintf(df, "tick %f\n", atrv->value.d);
+                               fprintf(df, "tick %g\n", atrv->value.d);
                                break;
 
                                case T_Driftfile:
@@ -1424,7 +1387,7 @@ dump_config_tree(
                                break;
                        
                                case T_WanderThreshold:
-                               fprintf(df, "wander_threshold %f\n", atrv->value.d);
+                               fprintf(df, "wander_threshold %g\n", atrv->value.d);
                                break;
        
                                case T_Leapfile:
index 65f3d356855cfa5e82a1724865fa402b0af1fb67..cb25828b869a91d9fddeace3f502e59964817af1 100644 (file)
@@ -125,6 +125,9 @@ void        uninit_util(void);
 void
 uninit_util(void)
 {
+#if defined(_MSC_VER) && defined (_DEBUG)
+       _CrtCheckMemory();
+#endif
        if (stats_drift_file) {
                free(stats_drift_file);
                free(stats_temp_file);
@@ -147,6 +150,10 @@ uninit_util(void)
 #ifdef DEBUG_TIMING
        filegen_unregister("timingstats");
 #endif /* DEBUG_TIMING */
+
+#if defined(_MSC_VER) && defined (_DEBUG)
+       _CrtCheckMemory();
+#endif
 }
 #endif /* DEBUG */
 
index 9d5bb469e2bfb1e7b6eeece61c1f1167b99b4243..c0329bb61ce26aa68ea77cda7acd05e088d2c2be 100644 (file)
@@ -366,17 +366,31 @@ free_io_completion_port_mem(
 {
        IoCompletionInfo *      pci;
 
+#if defined(_MSC_VER) && defined (_DEBUG)
+       _CrtCheckMemory();
+#endif
        LOCK_COMPL();
        while ((pci = compl_info_list) != NULL) {
 
+#if 0  /* sockaddr with received-from address in recvbuf */
+       /* is sometimes modified by system after we free it  */
+       /* triggering heap corruption warning -- find a */
+       /* better way to free it after I/O is surely done */
                /* this handles both xmit and recv buffs */
-               if (pci->recv_buf != NULL)
+               if (pci->recv_buf != NULL) {
+                       DPRINTF(1, ("freeing xmit/recv buff %p\n", pci->recv_buf));
                        free(pci->recv_buf);
+               }
+#endif
 
                FreeHeap(pci, "free_io_completion_port_mem");
                /* FreeHeap() removed this item from compl_info_list */
        }
        UNLOCK_COMPL()
+
+#if defined(_MSC_VER) && defined (_DEBUG)
+       _CrtCheckMemory();
+#endif
 }
 #endif /* DEBUG */