@@ -1556,7 +1556,35 @@ static int tile_handler_serve(request_rec *r)
15561556 gettimeofday (& start , NULL );
15571557
15581558 // FIXME: It is a waste to do the malloc + read if we are fulfilling a HEAD or returning a 304.
1559+ #ifdef __MACH__
1560+ /*
1561+ * macOS Compatibility: Create a dedicated allocator and independent pool for the tile buffer.
1562+ * The allocator's max_free is limited to prevent memory fragmentation during high traffic.
1563+ */
1564+ apr_pool_t * tp ;
1565+ apr_allocator_t * pa ;
1566+
1567+ if (apr_allocator_create (& pa ) != APR_SUCCESS ) {
1568+ ap_log_rerror (APLOG_MARK , APLOG_WARNING , 0 , r ,
1569+ "Failed to create tile buffer allocator" );
1570+ return HTTP_INTERNAL_SERVER_ERROR ;
1571+ }
1572+
1573+ apr_allocator_max_free_set (pa , 1 );
1574+
1575+ if (apr_pool_create_ex (& tp , NULL , NULL , pa ) != APR_SUCCESS ) {
1576+ ap_log_rerror (APLOG_MARK , APLOG_WARNING , 0 , r ,
1577+ "Failed to create tile buffer pool" );
1578+ apr_allocator_destroy (pa );
1579+ return HTTP_INTERNAL_SERVER_ERROR ;
1580+ }
1581+
1582+ apr_allocator_owner_set (pa , tp );
1583+
1584+ buf = (char * )apr_palloc (tp , tile_max );
1585+ #else
15591586 buf = (char * )apr_pcalloc (r -> pool , tile_max );
1587+ #endif
15601588
15611589 if (!buf ) {
15621590 if (!incRespCounter (HTTP_INTERNAL_SERVER_ERROR , r , cmd , rdata -> layerNumber )) {
@@ -1607,6 +1635,10 @@ static int tile_handler_serve(request_rec *r)
16071635 incTimingCounter ((end .tv_sec * 1000000 + end .tv_usec ) - (start .tv_sec * 1000000 + start .tv_usec ), cmd -> z , r );
16081636
16091637 if ((errstatus = ap_meets_conditions (r )) != OK ) {
1638+ #ifdef __MACH__
1639+ apr_pool_destroy (tp );
1640+ #endif
1641+
16101642 if (!incRespCounter (errstatus , r , cmd , rdata -> layerNumber )) {
16111643 ap_log_rerror (APLOG_MARK , APLOG_WARNING , 0 , r ,
16121644 "Failed to increase response stats counter" );
@@ -1615,6 +1647,9 @@ static int tile_handler_serve(request_rec *r)
16151647 return errstatus ;
16161648 } else {
16171649 ap_rwrite (buf , len , r );
1650+ #ifdef __MACH__
1651+ apr_pool_destroy (tp );
1652+ #endif
16181653
16191654 if (!incRespCounter (errstatus , r , cmd , rdata -> layerNumber )) {
16201655 ap_log_rerror (APLOG_MARK , APLOG_WARNING , 0 , r ,
@@ -1625,6 +1660,9 @@ static int tile_handler_serve(request_rec *r)
16251660 }
16261661 }
16271662
1663+ #ifdef __MACH__
1664+ apr_pool_destroy (tp );
1665+ #endif
16281666 ap_log_rerror (APLOG_MARK , APLOG_WARNING , 0 , r , "Failed to read tile from disk: %s" , err_msg );
16291667
16301668 if (!incRespCounter (HTTP_NOT_FOUND , r , cmd , rdata -> layerNumber )) {
0 commit comments