]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
[v9_10] fix 'total use' accounting
authorEvan Hunt <each@isc.org>
Thu, 22 Jan 2015 17:46:28 +0000 (09:46 -0800)
committerEvan Hunt <each@isc.org>
Thu, 22 Jan 2015 17:46:28 +0000 (09:46 -0800)
4046.   [bug]           Accounting of "total use" in memory context
                        statistics was not correct. [RT #38370]

CHANGES
bin/named/main.c
lib/isc/mem.c
lib/isc/tests/Makefile.in
lib/isc/tests/mem_test.c [new file with mode: 0644]

diff --git a/CHANGES b/CHANGES
index c8040da0a2ba205ba1465831e18a1dc44a4da4ce..8150a265d672353d8a1c08a57a466ffee15ad549 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,3 +1,6 @@
+4046.  [bug]           Accounting of "total use" in memory context
+                       statistics was not correct. [RT #38370]
+
 4045.  [bug]           Skip to next master on dns_request_createvia4 failure.
                        [RT #25185]
 
index dee41be4d3b71efcdfe71dcff5af2a7b0e355b1c..9187cbf89f86645adc78c8788a0dd9ffa5997734 100644 (file)
@@ -81,6 +81,7 @@
 
 #ifdef OPENSSL
 #include <openssl/opensslv.h>
+#include <openssl/crypto.h>
 #endif
 #ifdef HAVE_LIBXML2
 #include <libxml/xmlversion.h>
@@ -602,12 +603,16 @@ parse_command_line(int argc, char *argv[]) {
                        printf("compiled by Solaris Studio %x\n", __SUNPRO_C);
 #endif
 #ifdef OPENSSL
-                       printf("using OpenSSL version: %s\n",
+                       printf("compiled with OpenSSL version: %s\n",
                               OPENSSL_VERSION_TEXT);
+                       printf("linked to OpenSSL version: %s\n",
+                              SSLeay_version(SSLEAY_VERSION));
 #endif
 #ifdef HAVE_LIBXML2
-                       printf("using libxml2 version: %s\n",
+                       printf("compiled with libxml2 version: %s\n",
                               LIBXML_DOTTED_VERSION);
+                       printf("linked to libxml2 version: %s\n",
+                              xmlParserVersion);
 #endif
                        exit(0);
                case 'F':
index 07975ee43ce300fda92448af415ab65e993921a7..67f36f411ff9f5cf1f530c09beababa1147c0e0c 100644 (file)
@@ -741,9 +741,8 @@ mem_putunlocked(isc__mem_t *ctx, void *mem, size_t size) {
                (ctx->memfree)(ctx->arg, mem);
                INSIST(ctx->stats[ctx->max_size].gets != 0U);
                ctx->stats[ctx->max_size].gets--;
-               INSIST(size <= ctx->total);
+               INSIST(size <= ctx->inuse);
                ctx->inuse -= size;
-               ctx->total -= size;
                return;
        }
 
index 22cc7a1edec99989da1ea06a4a43bd16f59d0cd2..452250832c2061c277039df409c9a4809b688c1b 100644 (file)
@@ -12,8 +12,6 @@
 # OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
 # PERFORMANCE OF THIS SOFTWARE.
 
-# $Id$
-
 srcdir =       @srcdir@
 VPATH =                @srcdir@
 top_srcdir =   @top_srcdir@
@@ -40,7 +38,7 @@ SRCS =                isctest.c taskpool_test.c socket_test.c hash_test.c \
                sockaddr_test.c symtab_test.c task_test.c queue_test.c \
                parse_test.c pool_test.c print_test.c regex_test.c \
                socket_test.c safe_test.c time_test.c aes_test.c \
-               counter_test.c
+               counter_test.c mem_test.c
 
 SUBDIRS =
 TARGETS =      taskpool_test@EXEEXT@ socket_test@EXEEXT@ hash_test@EXEEXT@ \
@@ -49,7 +47,7 @@ TARGETS =     taskpool_test@EXEEXT@ socket_test@EXEEXT@ hash_test@EXEEXT@ \
                queue_test@EXEEXT@ parse_test@EXEEXT@ pool_test@EXEEXT@ \
                print_test@EXEEXT@ regex_test@EXEEXT@ socket_test@EXEEXT@ \
                safe_test@EXEEXT@ time_test@EXEEXT@ aes_test@EXEEXT@ \
-               counter_test@EXEEXT@
+               counter_test@EXEEXT@ mem_test@EXEEXT@
 
 @BIND9_MAKE_RULES@
 
@@ -121,6 +119,10 @@ counter_test@EXEEXT@: counter_test.@O@ ${ISCDEPLIBS}
        ${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${LDFLAGS} -o $@ \
                        counter_test.@O@ isctest.@O@ ${ISCLIBS} ${LIBS}
 
+mem_test@EXEEXT@: mem_test.@O@ ${ISCDEPLIBS}
+       ${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${LDFLAGS} -o $@ \
+                       mem_test.@O@ isctest.@O@ ${ISCLIBS} ${LIBS}
+
 unit::
        sh ${top_srcdir}/unit/unittest.sh
 
diff --git a/lib/isc/tests/mem_test.c b/lib/isc/tests/mem_test.c
new file mode 100644 (file)
index 0000000..49190cf
--- /dev/null
@@ -0,0 +1,156 @@
+/*
+ * Copyright (C) 2014  Internet Systems Consortium, Inc. ("ISC")
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
+ * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
+ * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
+ * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
+ * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+ * PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <config.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <fcntl.h>
+
+#include <atf-c.h>
+
+#include "isctest.h"
+
+#include <isc/mem.h>
+#include <isc/result.h>
+
+static void *
+default_memalloc(void *arg, size_t size) {
+       UNUSED(arg);
+       if (size == 0U)
+               size = 1;
+       return (malloc(size));
+}
+
+static void
+default_memfree(void *arg, void *ptr) {
+       UNUSED(arg);
+       free(ptr);
+}
+
+ATF_TC(isc_mem_total);
+ATF_TC_HEAD(isc_mem_total, tc) {
+       atf_tc_set_md_var(tc, "descr", "test TotalUse calculation");
+}
+
+ATF_TC_BODY(isc_mem_total, tc) {
+       isc_result_t result;
+       isc_mem_t *mctx2 = NULL;
+       size_t before, after;
+       ssize_t diff;
+       int i;
+
+       result = isc_test_begin(NULL, ISC_TRUE);
+       ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
+
+       /* Local alloc, free */
+       mctx2 = NULL;
+       result = isc_mem_createx2(0, 0, default_memalloc, default_memfree,
+                                 NULL, &mctx2, 0);
+       if (result != ISC_R_SUCCESS)
+               goto out;
+
+       before = isc_mem_total(mctx2);
+
+       for (i = 0; i < 100000; i++) {
+               void *ptr;
+
+               ptr = isc_mem_allocate(mctx2, 2048);
+               isc_mem_free(mctx2, ptr);
+       }
+
+       after = isc_mem_total(mctx2);
+       diff = after - before;
+
+       printf("total_before=%lu, total_after=%lu, total_diff=%lu\n",
+              before, after, diff);
+       /* 2048 +8 bytes extra for size_info */
+       ATF_CHECK_EQ(diff, (2048 + 8) * 100000);
+
+       /* ISC_MEMFLAG_INTERNAL */
+
+       before = isc_mem_total(mctx);
+
+       for (i = 0; i < 100000; i++) {
+               void *ptr;
+
+               ptr = isc_mem_allocate(mctx, 2048);
+               isc_mem_free(mctx, ptr);
+       }
+
+       after = isc_mem_total(mctx);
+       diff = after - before;
+
+       printf("total_before=%lu, total_after=%lu, total_diff=%lu\n",
+              before, after, diff);
+       /* 2048 +8 bytes extra for size_info */
+       ATF_CHECK_EQ(diff, (2048 + 8) * 100000);
+
+ out:
+       if (mctx2 != NULL)
+               isc_mem_destroy(&mctx2);
+
+       isc_test_end();
+}
+
+ATF_TC(isc_mem_inuse);
+ATF_TC_HEAD(isc_mem_inuse, tc) {
+       atf_tc_set_md_var(tc, "descr", "test InUse calculation");
+}
+
+ATF_TC_BODY(isc_mem_inuse, tc) {
+       isc_result_t result;
+       isc_mem_t *mctx2 = NULL;
+       size_t before, during, after;
+       ssize_t diff;
+       void *ptr;
+
+       result = isc_test_begin(NULL, ISC_TRUE);
+       ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
+
+       mctx2 = NULL;
+       result = isc_mem_createx2(0, 0, default_memalloc, default_memfree,
+                                 NULL, &mctx2, 0);
+       if (result != ISC_R_SUCCESS)
+               goto out;
+
+       before = isc_mem_inuse(mctx2);
+       ptr = isc_mem_allocate(mctx2, 1024000);
+       during = isc_mem_inuse(mctx2);
+       isc_mem_free(mctx2, ptr);
+       after = isc_mem_inuse(mctx2);
+
+       diff = after - before;
+
+       printf("inuse_before=%lu, inuse_during=%lu, inuse_after=%lu\n",
+              before, during, after);
+       ATF_REQUIRE_EQ(diff, 0);
+
+ out:
+       if (mctx2 != NULL)
+               isc_mem_destroy(&mctx2);
+
+       isc_test_end();
+}
+
+/*
+ * Main
+ */
+ATF_TP_ADD_TCS(tp) {
+       ATF_TP_ADD_TC(tp, isc_mem_total);
+       ATF_TP_ADD_TC(tp, isc_mem_inuse);
+
+       return (atf_no_error());
+}