]> 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:50:24 +0000 (17:50 +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)
(cherry picked from commit f7903e4bcc80523d7786e66f24fc090a36889fed)

CHANGES
bin/tests/mdig.c
lib/dns/openssl_link.c

diff --git a/CHANGES b/CHANGES
index 50ae1b32ac02d160618b0389f75fa59abb40af54..da987284ddfa1301ea8e60e8cc092f8658021460 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 a7bd08a01ac6390ec4eaee90256d7f1dcd7b2334..261a93f8addf67b3e81d8a6c130be02e76c9e7b8 100644 (file)
@@ -735,6 +735,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]vc             (TCP mode)\n"
 "                 +[no]tcp            (TCP mode, alternate syntax)\n"
 "                 +[no]besteffort     (Try to parse even illegal messages)\n"
@@ -1482,7 +1483,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,
@@ -1539,6 +1540,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':
                        exit(0);
                        break;
@@ -1655,6 +1661,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)
 {
@@ -1831,8 +1870,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 0e7009fea9f6d26467f538dc995d565ce9c9a6b0..e6df08a451a6960985eebf8d14690171c8e9bea0 100644 (file)
@@ -131,10 +131,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