]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
4560. [bug] mdig: add -m option to enable memory debugging rather
authorMark Andrews <marka@isc.org>
Tue, 24 Jan 2017 06:48:31 +0000 (17:48 +1100)
committerMark Andrews <marka@isc.org>
Tue, 24 Jan 2017 06:49:08 +0000 (17:49 +1100)
                        than have in on all the time. [RT #44509]

4559.   [bug]           Openssl_link.c didn't compile if ISC_MEM_TRACKLINES
                        was turned off.  [RT #44509]

(cherry picked from commit 25da687db7a12ac3c987b088d99055ba634d0b5c)

CHANGES
bin/tools/mdig.c
bin/tools/mdig.docbook
lib/dns/openssl_link.c

diff --git a/CHANGES b/CHANGES
index 933121394914726b65250881637d3fcf62d55521..ea45218e230ee04e5584a0feb1675247abb183fa 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,3 +1,9 @@
+4560.  [bug]           mdig: add -m option to enable memory debugging rather
+                       than have in on all the time. [RT #44509]
+
+4559.  [bug]           Openssl_link.c didn't compile if ISC_MEM_TRACKLINES
+                       was turned off.  [RT #44509]
+
 4558.  [bug]           Synthesised CNAME before matching DNAME was still
                        being cached when it should have been.  [RT #44318]
 
index eaf477caae876289937258cf70702e0f841e0f1e..08a47b475084b55e41c14393332d73d8504d8c3d 100644 (file)
@@ -742,6 +742,7 @@ help(void) {
 "                 -6                  (use IPv6 query transport only)\n"
 "                 -b address[#port]   (bind to source address/port)\n"
 "                 -p port             (specify port number)\n"
+"                 -m                  (enable memory usage debugging)\n"
 "                 +[no]dscp[=###]     (Set the DSCP value to ### [0..63])\n"
 "                 +[no]vc             (TCP mode)\n"
 "                 +[no]tcp            (TCP mode, alternate syntax)\n"
@@ -1520,7 +1521,7 @@ plus_option(char *option, struct query *query, isc_boolean_t global)
 /*%
  * #ISC_TRUE returned if value was used
  */
-static const char *single_dash_opts = "46hiv";
+static const char *single_dash_opts = "46himv";
 /*static const char *dash_opts = "46bcfhiptvx";*/
 static isc_boolean_t
 dash_option(const char *option, char *next, struct query *query,
@@ -1577,6 +1578,11 @@ dash_option(const char *option, char *next, struct query *query,
                case 'i':
                        query->ip6_int = ISC_TRUE;
                        break;
+               case 'm':
+                       /*
+                        * handled by preparse_args()
+                        */
+                       break;
                case 'v':
                        fputs("mDiG " VERSION "\n", stderr);
                        exit(0);
@@ -1694,6 +1700,39 @@ clone_default_query() {
        return query;
 }
 
+/*%
+ * Because we may be trying to do memory allocation recording, we're going
+ * to need to parse the arguments for the -m *before* we start the main
+ * argument parsing routine.
+ *
+ * I'd prefer not to have to do this, but I am not quite sure how else to
+ * fix the problem.  Argument parsing in mdig involves memory allocation
+ * by its nature, so it can't be done in the main argument parser.
+ */
+static void
+preparse_args(int argc, char **argv) {
+       int rc;
+       char **rv;
+       char *option;
+
+       rc = argc;
+       rv = argv;
+       for (rc--, rv++; rc > 0; rc--, rv++) {
+               if (rv[0][0] != '-')
+                       continue;
+               option = &rv[0][1];
+               while (strpbrk(option, single_dash_opts) == &option[0]) {
+                       switch (option[0]) {
+                       case 'm':
+                               isc_mem_debugging = ISC_MEM_DEBUGTRACE |
+                                       ISC_MEM_DEBUGRECORD;
+                               break;
+                       }
+                       option = &option[1];
+               }
+       }
+}
+
 static void
 parse_args(isc_boolean_t is_batchfile, int argc, char **argv)
 {
@@ -1870,8 +1909,9 @@ main(int argc, char *argv[]) {
        if (!have_ipv4 && !have_ipv6)
                fatal("could not find either IPv4 or IPv6");
 
+       preparse_args(argc, argv);
+
        mctx = NULL;
-isc_mem_debugging = ISC_MEM_DEBUGRECORD;
        RUNCHECK(isc_mem_create(0, 0, &mctx));
 
        lctx = NULL;
index 19f8a819045cc05a30314ca98c478a3c52799c30..a650732883a59c7f73f41a8d3534ce3c6591ae0f 100644 (file)
@@ -44,6 +44,7 @@
       <arg choice="opt" rep="norepeat"><option>-v</option></arg>
       <arg choice="opt" rep="norepeat"><option>-4</option></arg>
       <arg choice="opt" rep="norepeat"><option>-6</option></arg>
+      <arg choice="opt" rep="norepeat"><option>-m</option></arg>
       <arg choice="opt" rep="norepeat"><option>-b <replaceable class="parameter">address</replaceable></option></arg>
       <arg choice="opt" rep="norepeat"><option>-p <replaceable class="parameter">port#</replaceable></option></arg>
       <arg choice="opt" rep="norepeat"><option>-c <replaceable class="parameter">class</replaceable></option></arg>
       "#&lt;port&gt;"
     </para>
 
+    <para>
+      The <option>-m</option> option enables memory usage debugging.
+    </para>
+
     <para>
       The <option>-p</option> option is used when a non-standard port
       number is to be queried.
index 29facf3a7e9206201c5e361e2f00295dab0d69a0..4e0976edab44d9e4c89500ccb4511359af857a3e 100644 (file)
@@ -122,10 +122,17 @@ id_callback(void) {
 #endif
 
 #if OPENSSL_VERSION_NUMBER < 0x10100000L || defined(LIBRESSL_VERSION_NUMBER)
-#define FLARG_PASS      , __FILE__, __LINE__
+
 #define FLARG
 #define FILELINE
+#if ISC_MEM_TRACKLINES
+#define FLARG_PASS      , __FILE__, __LINE__
 #else
+#define FLARG_PASS
+#endif
+
+#else
+
 #define FLARG           , const char *file, int line
 #define FILELINE       , __FILE__, __LINE__
 #if ISC_MEM_TRACKLINES