@@ -551,7 +551,7 @@ static void add_expiry(request_rec *r, struct protocol *cmd)
551551
552552 apr_table_mergen (t , "Cache-Control" ,
553553 apr_psprintf (r -> pool , "max-age=%li" , maxAge ));
554- timestr = (char * )apr_palloc (r -> pool , APR_RFC822_DATE_LEN );
554+ timestr = (char * )apr_pcalloc (r -> pool , APR_RFC822_DATE_LEN );
555555 apr_rfc822_date (timestr , (apr_time_from_sec (maxAge ) + r -> request_time ));
556556 apr_table_setn (t , "Expires" , timestr );
557557}
@@ -1301,7 +1301,7 @@ static int tile_handler_json(request_rec *r)
13011301 }
13021302 }
13031303
1304- buf = (char * )apr_palloc (r -> pool , 8 * 1024 );
1304+ buf = (char * )apr_pcalloc (r -> pool , 8 * 1024 );
13051305
13061306 snprintf (buf , 8 * 1024 ,
13071307 "{\n"
@@ -1343,22 +1343,41 @@ static int tile_handler_json(request_rec *r)
13431343 ap_set_content_length (r , len );
13441344 apr_table_mergen (t , "Cache-Control" ,
13451345 apr_psprintf (r -> pool , "max-age=%li" , maxAge ));
1346- timestr = (char * )apr_palloc (r -> pool , APR_RFC822_DATE_LEN );
1346+ timestr = (char * )apr_pcalloc (r -> pool , APR_RFC822_DATE_LEN );
13471347 apr_rfc822_date (timestr , (apr_time_from_sec (maxAge ) + r -> request_time ));
13481348 apr_table_setn (t , "Expires" , timestr );
13491349 ap_rwrite (buf , len , r );
13501350
13511351 return OK ;
13521352}
13531353
1354+ static int _get_stats_copy (request_rec * r , tile_server_conf * scfg , stats_data * * stats_copy ) {
1355+ stats_data * stats ;
1356+ unsigned long sizeof_config_elements ;
1357+
1358+ if (get_global_lock (r , stats_mutex ) != 0 ) {
1359+ // Copy over the global counter variable into
1360+ // local variables, that we can immediately
1361+ // release the lock again
1362+ sizeof_config_elements = sizeof (apr_uint64_t ) * scfg -> configs -> nelts ;
1363+ stats = (stats_data * )apr_shm_baseaddr_get (stats_shm );
1364+ * stats_copy = (stats_data * )apr_pmemdup (r -> pool , stats , sizeof (stats_data ));
1365+ (* stats_copy )-> noResp200Layer = (apr_uint64_t * )apr_pmemdup (r -> pool , stats -> noResp200Layer , sizeof_config_elements );
1366+ (* stats_copy )-> noResp404Layer = (apr_uint64_t * )apr_pmemdup (r -> pool , stats -> noResp404Layer , sizeof_config_elements );
1367+ apr_global_mutex_unlock (stats_mutex );
1368+ } else {
1369+ return error_message (r , "Failed to acquire lock, can't copy stats" );
1370+ }
1371+
1372+ return OK ;
1373+ }
1374+
13541375static int tile_handler_mod_stats (request_rec * r )
13551376{
1356- stats_data * stats ;
1357- stats_data * local_stats ;
13581377 int i ;
1359- unsigned long sizeof_config_elements ;
1360- tile_server_conf * scfg ;
1378+ stats_data * local_stats ;
13611379 tile_config_rec * tile_configs ;
1380+ tile_server_conf * scfg ;
13621381
13631382 if (strcmp (r -> handler , "tile_mod_stats" )) {
13641383 return DECLINED ;
@@ -1371,18 +1390,10 @@ static int tile_handler_mod_stats(request_rec *r)
13711390 return error_message (r , "Stats are not enabled for this server" );
13721391 }
13731392
1374- if (get_global_lock (r , stats_mutex ) != 0 ) {
1375- // Copy over the global counter variable into
1376- // local variables, that we can immediately
1377- // release the lock again
1378- sizeof_config_elements = sizeof (apr_uint64_t ) * scfg -> configs -> nelts ;
1379- stats = (stats_data * )apr_shm_baseaddr_get (stats_shm );
1380- local_stats = (stats_data * )apr_pmemdup (r -> pool , stats , sizeof (stats_data ));
1381- local_stats -> noResp200Layer = (apr_uint64_t * )apr_pmemdup (r -> pool , stats -> noResp200Layer , sizeof_config_elements );
1382- local_stats -> noResp404Layer = (apr_uint64_t * )apr_pmemdup (r -> pool , stats -> noResp404Layer , sizeof_config_elements );
1383- apr_global_mutex_unlock (stats_mutex );
1384- } else {
1385- return error_message (r , "Failed to acquire lock, can't display stats" );
1393+ _get_stats_copy (r , scfg , & local_stats );
1394+
1395+ if (!local_stats ) {
1396+ return OK ;
13861397 }
13871398
13881399 ap_rprintf (r , "NoResp200: %" APR_UINT64_T_FMT "\n" , local_stats -> noResp200 );
@@ -1421,12 +1432,10 @@ static int tile_handler_mod_stats(request_rec *r)
14211432
14221433static int tile_handler_metrics (request_rec * r )
14231434{
1424- stats_data * stats ;
1425- stats_data * local_stats ;
14261435 int i ;
1427- unsigned long sizeof_config_elements ;
1428- tile_server_conf * scfg ;
1436+ stats_data * local_stats ;
14291437 tile_config_rec * tile_configs ;
1438+ tile_server_conf * scfg ;
14301439
14311440 if (strcmp (r -> handler , "tile_metrics" )) {
14321441 return DECLINED ;
@@ -1439,18 +1448,10 @@ static int tile_handler_metrics(request_rec *r)
14391448 return error_message (r , "Stats are not enabled for this server" );
14401449 }
14411450
1442- if (get_global_lock (r , stats_mutex ) != 0 ) {
1443- // Copy over the global counter variable into
1444- // local variables, that we can immediately
1445- // release the lock again
1446- sizeof_config_elements = sizeof (apr_uint64_t ) * scfg -> configs -> nelts ;
1447- stats = (stats_data * )apr_shm_baseaddr_get (stats_shm );
1448- local_stats = (stats_data * )apr_pmemdup (r -> pool , stats , sizeof (stats_data ));
1449- local_stats -> noResp200Layer = (apr_uint64_t * )apr_pmemdup (r -> pool , stats -> noResp200Layer , sizeof_config_elements );
1450- local_stats -> noResp404Layer = (apr_uint64_t * )apr_pmemdup (r -> pool , stats -> noResp404Layer , sizeof_config_elements );
1451- apr_global_mutex_unlock (stats_mutex );
1452- } else {
1453- return error_message (r , "Failed to acquire lock, can't display stats" );
1451+ _get_stats_copy (r , scfg , & local_stats );
1452+
1453+ if (!local_stats ) {
1454+ return OK ;
14541455 }
14551456
14561457 ap_rprintf (r , "# HELP modtile_http_responses_total Number of HTTP responses by response code\n" );
@@ -1554,7 +1555,7 @@ static int tile_handler_serve(request_rec *r)
15541555 gettimeofday (& start , NULL );
15551556
15561557 // FIXME: It is a waste to do the malloc + read if we are fulfilling a HEAD or returning a 304.
1557- buf = (char * )apr_palloc (r -> pool , tile_max );
1558+ buf = (char * )apr_pcalloc (r -> pool , tile_max );
15581559
15591560 if (!buf ) {
15601561 if (!incRespCounter (HTTP_INTERNAL_SERVER_ERROR , r , cmd , rdata -> layerNumber )) {
@@ -1894,7 +1895,7 @@ static const char *_add_tile_config(cmd_parms *cmd,
18941895 tile_dir = apr_pstrndup (cmd -> pool , scfg -> tile_dir , PATH_MAX );
18951896 }
18961897
1897- char * * hostnames = (char * * )malloc ( sizeof (char * ) * hostnames_len );
1898+ char * * hostnames = (char * * )apr_pcalloc ( cmd -> pool , sizeof (char * ) * hostnames_len );
18981899
18991900 // Set first hostname to server_hostname value (if set,) otherwise use localhost
19001901 if (cmd -> server -> server_hostname == NULL ) {
@@ -2022,7 +2023,7 @@ static const char *load_tile_config(cmd_parms *cmd, void *mconfig, const char *c
20222023
20232024 xmlconfigitem maps [XMLCONFIGS_MAX ];
20242025
2025- process_map_sections (config_file_name , maps , "" , 0 );
2026+ process_map_sections (NULL , config_file_name , maps , "" , 0 );
20262027
20272028 for (int i = 0 ; i < XMLCONFIGS_MAX ; i ++ ) {
20282029 if (maps [i ].xmlname != NULL ) {
0 commit comments