From: Dave Hart Date: Sun, 16 Aug 2009 17:41:19 +0000 (+0000) Subject: Add extra heap-checking calls to atexit-invoked routines X-Git-Tag: NTP_4_2_5P203~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c995204c2d3e13fbf2476e22f9d31fec98efd9cc;p=thirdparty%2Fntp.git Add extra heap-checking calls to atexit-invoked routines 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 --- diff --git a/ntpd/ntp_config.c b/ntpd/ntp_config.c index 8617475a5..0bb00861b 100644 --- a/ntpd/ntp_config.c +++ b/ntpd/ntp_config.c @@ -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: diff --git a/ntpd/ntp_util.c b/ntpd/ntp_util.c index 65f3d3568..cb25828b8 100644 --- a/ntpd/ntp_util.c +++ b/ntpd/ntp_util.c @@ -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 */ diff --git a/ports/winnt/ntpd/ntp_iocompletionport.c b/ports/winnt/ntpd/ntp_iocompletionport.c index 9d5bb469e..c0329bb61 100644 --- a/ports/winnt/ntpd/ntp_iocompletionport.c +++ b/ports/winnt/ntpd/ntp_iocompletionport.c @@ -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 */