Update APR to 1.6.5. Disable pool debugging again in favour of a patch
by APR committer Yann Ylavic, which forces the default allocator to call
free(3) when memory is no longer needed. The pool debug feature also
enforces this, but has additional side-effects since it uses an entirely
different code path which upstream says should not be used in production.

Also, add my patch to fix a botched format string definition for off_t
which I suggested earlier: https://marc.info/?t=154496320200002&r=1&w=2
I have been talking to upstream about this, and it turns out that this
problem also affects Linux systems. So I expect that this will be fixed
upstream eventually. For now we can use a local patch.

OK?

Index: Makefile
===================================================================
RCS file: /cvs/ports/devel/apr/Makefile,v
retrieving revision 1.42
diff -u -p -r1.42 Makefile
--- Makefile    25 Oct 2017 19:36:46 -0000      1.42
+++ Makefile    17 Jan 2019 12:40:07 -0000
@@ -2,9 +2,8 @@
 
 COMMENT=       Apache Portable Runtime
 
-V=             1.6.3
+V=             1.6.5
 DISTNAME=      apr-$V
-REVISION=      0
 SHARED_LIBS += apr-1             6.0     # .6.2
 
 CATEGORIES=    devel
@@ -22,11 +21,12 @@ MASTER_SITES=       ${MASTER_SITE_APACHE:=apr/
 
 AUTOCONF_VERSION=2.69
 CONFIGURE_STYLE=autoconf autoheader
+# Prevent APR pools from re-using dynamic memory allocations:
+CFLAGS="-DAPR_ALLOCATOR_MAX_FREE_DEFAULT=1"
 CONFIGURE_ARGS=        --includedir=${LOCALBASE}/include/apr-1/ \
                --with-installbuilddir=${LOCALBASE}/lib/apr-1/ \
                --enable-other-child \
                --enable-threads \
-               --enable-pool-debug=yes \
                ac_cv_prog_AWK=awk
 MODGNU_CONFIG_GUESS_DIRS=${WRKSRC}/build
 
Index: distinfo
===================================================================
RCS file: /cvs/ports/devel/apr/distinfo,v
retrieving revision 1.13
diff -u -p -r1.13 distinfo
--- distinfo    23 Oct 2017 21:24:37 -0000      1.13
+++ distinfo    17 Jan 2019 11:54:44 -0000
@@ -1,2 +1,2 @@
-SHA256 (apr-1.6.3.tar.gz) = j9q8wABCFsNYi33KDyPRBN/gEqR+K7bxOCdTSm7nOqc=
-SIZE (apr-1.6.3.tar.gz) = 1072661
+SHA256 (apr-1.6.5.tar.gz) = cNz5ECBmov8v/EfpPCicjlTJXY3aI7UD+eYbsMvS0QU=
+SIZE (apr-1.6.5.tar.gz) = 1073556
Index: patches/patch-configure_in
===================================================================
RCS file: /cvs/ports/devel/apr/patches/patch-configure_in,v
retrieving revision 1.1
diff -u -p -r1.1 patch-configure_in
--- patches/patch-configure_in  25 Oct 2017 19:36:46 -0000      1.1
+++ patches/patch-configure_in  17 Jan 2019 12:39:28 -0000
@@ -3,7 +3,33 @@ $OpenBSD: patch-configure_in,v 1.1 2017/
 Index: configure.in
 --- configure.in.orig
 +++ configure.in
-@@ -2281,7 +2281,7 @@ fi
+@@ -1460,6 +1460,10 @@ case $host in
+     *)
+         AC_CHECK_FUNCS(mkstemp)
+         ;;
++    *-openbsd*)
++        off_t_fmt='#define APR_OFF_T_FMT APR_INT64_T_FMT'
++        off_t_strfn='apr_strtoi64'
++      ;;
+ esac
+ 
+ AC_SUBST(fork)
+@@ -1936,6 +1940,14 @@ elif test "$ac_cv_type_off_t" = "yes"; then
+         off_t_fmt='#define APR_OFF_T_FMT "I64d"'
+         off_t_strfn='_strtoi64'
+         ;;
++    *-openbsd*)
++        int64_t_fmt='#define APR_INT64_T_FMT "lld"'
++        uint64_t_fmt='#define APR_UINT64_T_FMT "llu"'
++        uint64_t_hex_fmt='#define APR_UINT64_T_HEX_FMT "llx"'
++        int64_value="long long"
++        long_value="long long"
++        int64_strfn="strtoll"
++      ;;
+     esac
+ else
+    # Fallback on int
+@@ -2289,7 +2301,7 @@ fi
  APR_IFALLYES(header:semaphore.h func:sem_open func:sem_close dnl
               func:sem_unlink func:sem_post func:sem_wait,
               hasposixser="1", hasposixser="0")
@@ -12,7 +38,7 @@ Index: configure.in
               hassysvser="0")
  APR_IFALLYES(func:flock define:LOCK_EX, hasflockser="1", hasflockser="0")
  APR_IFALLYES(header:fcntl.h define:F_SETLK, hasfcntlser="1", hasfcntlser="0")
-@@ -2470,6 +2470,8 @@ else
+@@ -2478,6 +2490,8 @@ else
  fi
  
  dnl ----------------------------- Checking for /dev/random 
@@ -21,7 +47,7 @@ Index: configure.in
  AC_MSG_CHECKING(for entropy source)
  
  why_no_rand=""
-@@ -2486,6 +2488,13 @@ AC_ARG_WITH(egd, 
+@@ -2494,6 +2508,13 @@ AC_ARG_WITH(egd, 
      AC_MSG_RESULT(EGD-compatible daemon)
      rand="1"
    ])
Index: patches/patch-include_apr_allocator_h
===================================================================
RCS file: patches/patch-include_apr_allocator_h
diff -N patches/patch-include_apr_allocator_h
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ patches/patch-include_apr_allocator_h       17 Jan 2019 11:58:15 -0000
@@ -0,0 +1,15 @@
+$OpenBSD$
+Add APR_ALLOCATOR_MAX_FREE_DEFAULT override to make APR pools call free(3).
+Index: include/apr_allocator.h
+--- include/apr_allocator.h.orig
++++ include/apr_allocator.h
+@@ -65,6 +65,9 @@ struct apr_memnode_t {
+ 
+ /** Symbolic constants */
+ #define APR_ALLOCATOR_MAX_FREE_UNLIMITED 0
++#ifndef APR_ALLOCATOR_MAX_FREE_DEFAULT
++#define APR_ALLOCATOR_MAX_FREE_DEFAULT APR_ALLOCATOR_MAX_FREE_UNLIMITED
++#endif
+ 
+ /**
+  * Create a new allocator
Index: patches/patch-memory_unix_apr_pools_c
===================================================================
RCS file: patches/patch-memory_unix_apr_pools_c
diff -N patches/patch-memory_unix_apr_pools_c
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ patches/patch-memory_unix_apr_pools_c       17 Jan 2019 12:16:37 -0000
@@ -0,0 +1,50 @@
+$OpenBSD$
+Force APR pools to always call free(3) when memory gets released.
+Index: memory/unix/apr_pools.c
+--- memory/unix/apr_pools.c.orig
++++ memory/unix/apr_pools.c
+@@ -127,8 +127,8 @@ struct apr_allocator_t {
+     apr_size_t        max_index;
+     /** Total size (in BOUNDARY_SIZE multiples) of unused memory before
+      * blocks are given back. @see apr_allocator_max_free_set().
+-     * @note Initialized to APR_ALLOCATOR_MAX_FREE_UNLIMITED,
+-     * which means to never give back blocks.
++     * @note Initialized to APR_ALLOCATOR_MAX_FREE_DEFAULT,
++     * which by default means to never give back blocks.
+      */
+     apr_size_t        max_free_index;
+     /**
+@@ -170,7 +170,7 @@ APR_DECLARE(apr_status_t) apr_allocator_create(apr_all
+         return APR_ENOMEM;
+ 
+     memset(new_allocator, 0, SIZEOF_ALLOCATOR_T);
+-    new_allocator->max_free_index = APR_ALLOCATOR_MAX_FREE_UNLIMITED;
++    new_allocator->max_free_index = APR_ALLOCATOR_MAX_FREE_DEFAULT;
+ 
+     *allocator = new_allocator;
+ 
+@@ -226,6 +226,7 @@ APR_DECLARE(apr_pool_t *) apr_allocator_owner_get(apr_
+ APR_DECLARE(void) apr_allocator_max_free_set(apr_allocator_t *allocator,
+                                              apr_size_t in_size)
+ {
++#ifndef __OpenBSD__
+     apr_size_t max_free_index;
+     apr_size_t size = in_size;
+ 
+@@ -248,6 +249,7 @@ APR_DECLARE(void) apr_allocator_max_free_set(apr_alloc
+     if (mutex != NULL)
+         apr_thread_mutex_unlock(mutex);
+ #endif
++#endif
+ }
+ 
+ static APR_INLINE
+@@ -1180,7 +1182,7 @@ APR_DECLARE(apr_status_t) apr_pool_create_unmanaged_ex
+             return APR_ENOMEM;
+         }
+         memset(pool_allocator, 0, SIZEOF_ALLOCATOR_T);
+-        pool_allocator->max_free_index = APR_ALLOCATOR_MAX_FREE_UNLIMITED;
++        pool_allocator->max_free_index = APR_ALLOCATOR_MAX_FREE_DEFAULT;
+     }
+     if ((node = allocator_alloc(pool_allocator,
+                                 MIN_ALLOC - APR_MEMNODE_T_SIZE)) == NULL) {

Reply via email to