@@ -1301,7 +1301,7 @@ static int tile_handler_json(request_rec *r)
13011301 }
13021302 }
13031303
1304- buf = (char * )malloc ( 8 * 1024 );
1304+ buf = (char * )apr_palloc ( r -> pool , 8 * 1024 );
13051305
13061306 snprintf (buf , 8 * 1024 ,
13071307 "{\n"
@@ -1347,16 +1347,16 @@ static int tile_handler_json(request_rec *r)
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 );
1350- free (buf );
13511350
13521351 return OK ;
13531352}
13541353
13551354static int tile_handler_mod_stats (request_rec * r )
13561355{
13571356 stats_data * stats ;
1358- stats_data local_stats ;
1357+ stats_data * local_stats ;
13591358 int i ;
1359+ unsigned long sizeof_config_elements ;
13601360 tile_server_conf * scfg ;
13611361 tile_config_rec * tile_configs ;
13621362
@@ -1375,58 +1375,56 @@ static int tile_handler_mod_stats(request_rec *r)
13751375 // Copy over the global counter variable into
13761376 // local variables, that we can immediately
13771377 // release the lock again
1378+ sizeof_config_elements = sizeof (apr_uint64_t ) * scfg -> configs -> nelts ;
13781379 stats = (stats_data * )apr_shm_baseaddr_get (stats_shm );
1379- memcpy (& local_stats , stats , sizeof (stats_data ));
1380- local_stats .noResp200Layer = (apr_uint64_t * )malloc (sizeof (apr_uint64_t ) * scfg -> configs -> nelts );
1381- memcpy (local_stats .noResp200Layer , stats -> noResp200Layer , sizeof (apr_uint64_t ) * scfg -> configs -> nelts );
1382- local_stats .noResp404Layer = (apr_uint64_t * )malloc (sizeof (apr_uint64_t ) * scfg -> configs -> nelts );
1383- memcpy (local_stats .noResp404Layer , stats -> noResp404Layer , sizeof (apr_uint64_t ) * scfg -> configs -> nelts );
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 );
13841383 apr_global_mutex_unlock (stats_mutex );
13851384 } else {
13861385 return error_message (r , "Failed to acquire lock, can't display stats" );
13871386 }
13881387
1389- ap_rprintf (r , "NoResp200: %" APR_UINT64_T_FMT "\n" , local_stats . noResp200 );
1390- ap_rprintf (r , "NoResp304: %" APR_UINT64_T_FMT "\n" , local_stats . noResp304 );
1391- ap_rprintf (r , "NoResp404: %" APR_UINT64_T_FMT "\n" , local_stats . noResp404 );
1392- ap_rprintf (r , "NoResp503: %" APR_UINT64_T_FMT "\n" , local_stats . noResp503 );
1393- ap_rprintf (r , "NoResp5XX: %" APR_UINT64_T_FMT "\n" , local_stats . noResp5XX );
1394- ap_rprintf (r , "NoRespOther: %" APR_UINT64_T_FMT "\n" , local_stats . noRespOther );
1395- ap_rprintf (r , "NoFreshCache: %" APR_UINT64_T_FMT "\n" , local_stats . noFreshCache );
1396- ap_rprintf (r , "NoOldCache: %" APR_UINT64_T_FMT "\n" , local_stats . noOldCache );
1397- ap_rprintf (r , "NoVeryOldCache: %" APR_UINT64_T_FMT "\n" , local_stats . noVeryOldCache );
1398- ap_rprintf (r , "NoFreshRender: %" APR_UINT64_T_FMT "\n" , local_stats . noFreshRender );
1399- ap_rprintf (r , "NoOldRender: %" APR_UINT64_T_FMT "\n" , local_stats . noOldRender );
1400- ap_rprintf (r , "NoVeryOldRender: %" APR_UINT64_T_FMT "\n" , local_stats . noVeryOldRender );
1388+ ap_rprintf (r , "NoResp200: %" APR_UINT64_T_FMT "\n" , local_stats -> noResp200 );
1389+ ap_rprintf (r , "NoResp304: %" APR_UINT64_T_FMT "\n" , local_stats -> noResp304 );
1390+ ap_rprintf (r , "NoResp404: %" APR_UINT64_T_FMT "\n" , local_stats -> noResp404 );
1391+ ap_rprintf (r , "NoResp503: %" APR_UINT64_T_FMT "\n" , local_stats -> noResp503 );
1392+ ap_rprintf (r , "NoResp5XX: %" APR_UINT64_T_FMT "\n" , local_stats -> noResp5XX );
1393+ ap_rprintf (r , "NoRespOther: %" APR_UINT64_T_FMT "\n" , local_stats -> noRespOther );
1394+ ap_rprintf (r , "NoFreshCache: %" APR_UINT64_T_FMT "\n" , local_stats -> noFreshCache );
1395+ ap_rprintf (r , "NoOldCache: %" APR_UINT64_T_FMT "\n" , local_stats -> noOldCache );
1396+ ap_rprintf (r , "NoVeryOldCache: %" APR_UINT64_T_FMT "\n" , local_stats -> noVeryOldCache );
1397+ ap_rprintf (r , "NoFreshRender: %" APR_UINT64_T_FMT "\n" , local_stats -> noFreshRender );
1398+ ap_rprintf (r , "NoOldRender: %" APR_UINT64_T_FMT "\n" , local_stats -> noOldRender );
1399+ ap_rprintf (r , "NoVeryOldRender: %" APR_UINT64_T_FMT "\n" , local_stats -> noVeryOldRender );
14011400
14021401 for (i = 0 ; i <= global_max_zoom ; i ++ ) {
1403- ap_rprintf (r , "NoRespZoom%02i: %" APR_UINT64_T_FMT "\n" , i , local_stats . noRespZoom [i ]);
1402+ ap_rprintf (r , "NoRespZoom%02i: %" APR_UINT64_T_FMT "\n" , i , local_stats -> noRespZoom [i ]);
14041403 }
14051404
1406- ap_rprintf (r , "NoTileBufferReads: %" APR_UINT64_T_FMT "\n" , local_stats . noTotalBufferRetrieval );
1407- ap_rprintf (r , "DurationTileBufferReads: %" APR_UINT64_T_FMT "\n" , local_stats . totalBufferRetrievalTime );
1405+ ap_rprintf (r , "NoTileBufferReads: %" APR_UINT64_T_FMT "\n" , local_stats -> noTotalBufferRetrieval );
1406+ ap_rprintf (r , "DurationTileBufferReads: %" APR_UINT64_T_FMT "\n" , local_stats -> totalBufferRetrievalTime );
14081407
14091408 for (i = 0 ; i <= global_max_zoom ; i ++ ) {
1410- ap_rprintf (r , "NoTileBufferReadZoom%02i: %" APR_UINT64_T_FMT "\n" , i , local_stats . noZoomBufferRetrieval [i ]);
1411- ap_rprintf (r , "DurationTileBufferReadZoom%02i: %" APR_UINT64_T_FMT "\n" , i , local_stats . zoomBufferRetrievalTime [i ]);
1409+ ap_rprintf (r , "NoTileBufferReadZoom%02i: %" APR_UINT64_T_FMT "\n" , i , local_stats -> noZoomBufferRetrieval [i ]);
1410+ ap_rprintf (r , "DurationTileBufferReadZoom%02i: %" APR_UINT64_T_FMT "\n" , i , local_stats -> zoomBufferRetrievalTime [i ]);
14121411 }
14131412
14141413 for (i = 0 ; i < scfg -> configs -> nelts ; ++ i ) {
14151414 tile_config_rec * tile_config = & tile_configs [i ];
1416- ap_rprintf (r , "NoRes200Layer%s: %" APR_UINT64_T_FMT "\n" , tile_config -> baseuri , local_stats . noResp200Layer [i ]);
1417- ap_rprintf (r , "NoRes404Layer%s: %" APR_UINT64_T_FMT "\n" , tile_config -> baseuri , local_stats . noResp404Layer [i ]);
1415+ ap_rprintf (r , "NoRes200Layer%s: %" APR_UINT64_T_FMT "\n" , tile_config -> baseuri , local_stats -> noResp200Layer [i ]);
1416+ ap_rprintf (r , "NoRes404Layer%s: %" APR_UINT64_T_FMT "\n" , tile_config -> baseuri , local_stats -> noResp404Layer [i ]);
14181417 }
14191418
1420- free (local_stats .noResp200Layer );
1421- free (local_stats .noResp404Layer );
14221419 return OK ;
14231420}
14241421
14251422static int tile_handler_metrics (request_rec * r )
14261423{
14271424 stats_data * stats ;
1428- stats_data local_stats ;
1425+ stats_data * local_stats ;
14291426 int i ;
1427+ unsigned long sizeof_config_elements ;
14301428 tile_server_conf * scfg ;
14311429 tile_config_rec * tile_configs ;
14321430
@@ -1445,67 +1443,64 @@ static int tile_handler_metrics(request_rec *r)
14451443 // Copy over the global counter variable into
14461444 // local variables, that we can immediately
14471445 // release the lock again
1446+ sizeof_config_elements = sizeof (apr_uint64_t ) * scfg -> configs -> nelts ;
14481447 stats = (stats_data * )apr_shm_baseaddr_get (stats_shm );
1449- memcpy (& local_stats , stats , sizeof (stats_data ));
1450- local_stats .noResp200Layer = (apr_uint64_t * )malloc (sizeof (apr_uint64_t ) * scfg -> configs -> nelts );
1451- memcpy (local_stats .noResp200Layer , stats -> noResp200Layer , sizeof (apr_uint64_t ) * scfg -> configs -> nelts );
1452- local_stats .noResp404Layer = (apr_uint64_t * )malloc (sizeof (apr_uint64_t ) * scfg -> configs -> nelts );
1453- memcpy (local_stats .noResp404Layer , stats -> noResp404Layer , sizeof (apr_uint64_t ) * scfg -> configs -> nelts );
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 );
14541451 apr_global_mutex_unlock (stats_mutex );
14551452 } else {
14561453 return error_message (r , "Failed to acquire lock, can't display stats" );
14571454 }
14581455
14591456 ap_rprintf (r , "# HELP modtile_http_responses_total Number of HTTP responses by response code\n" );
14601457 ap_rprintf (r , "# TYPE modtile_http_responses_total counter\n" );
1461- ap_rprintf (r , "modtile_http_responses_total{status=\"200\"} %" APR_UINT64_T_FMT "\n" , local_stats . noResp200 );
1462- ap_rprintf (r , "modtile_http_responses_total{status=\"304\"} %" APR_UINT64_T_FMT "\n" , local_stats . noResp304 );
1463- ap_rprintf (r , "modtile_http_responses_total{status=\"404\"} %" APR_UINT64_T_FMT "\n" , local_stats . noResp404 );
1464- ap_rprintf (r , "modtile_http_responses_total{status=\"503\"} %" APR_UINT64_T_FMT "\n" , local_stats . noResp503 );
1465- ap_rprintf (r , "modtile_http_responses_total{status=\"5XX\"} %" APR_UINT64_T_FMT "\n" , local_stats . noResp5XX );
1466- ap_rprintf (r , "modtile_http_responses_total{status=\"other\"} %" APR_UINT64_T_FMT "\n" , local_stats . noRespOther );
1458+ ap_rprintf (r , "modtile_http_responses_total{status=\"200\"} %" APR_UINT64_T_FMT "\n" , local_stats -> noResp200 );
1459+ ap_rprintf (r , "modtile_http_responses_total{status=\"304\"} %" APR_UINT64_T_FMT "\n" , local_stats -> noResp304 );
1460+ ap_rprintf (r , "modtile_http_responses_total{status=\"404\"} %" APR_UINT64_T_FMT "\n" , local_stats -> noResp404 );
1461+ ap_rprintf (r , "modtile_http_responses_total{status=\"503\"} %" APR_UINT64_T_FMT "\n" , local_stats -> noResp503 );
1462+ ap_rprintf (r , "modtile_http_responses_total{status=\"5XX\"} %" APR_UINT64_T_FMT "\n" , local_stats -> noResp5XX );
1463+ ap_rprintf (r , "modtile_http_responses_total{status=\"other\"} %" APR_UINT64_T_FMT "\n" , local_stats -> noRespOther );
14671464
14681465 ap_rprintf (r , "# HELP modtile_tiles_total Tiles served\n" );
14691466 ap_rprintf (r , "# TYPE modtile_tiles_total counter\n" );
1470- ap_rprintf (r , "modtile_tiles_total{age=\"fresh\",rendered=\"no\"} %" APR_UINT64_T_FMT "\n" , local_stats . noFreshCache );
1471- ap_rprintf (r , "modtile_tiles_total{age=\"old\",rendered=\"no\"} %" APR_UINT64_T_FMT "\n" , local_stats . noOldCache );
1472- ap_rprintf (r , "modtile_tiles_total{age=\"outdated\",rendered=\"no\"} %" APR_UINT64_T_FMT "\n" , local_stats . noVeryOldCache );
1473- ap_rprintf (r , "modtile_tiles_total{age=\"fresh\",rendered=\"yes\"} %" APR_UINT64_T_FMT "\n" , local_stats . noFreshRender );
1474- ap_rprintf (r , "modtile_tiles_total{age=\"old\",rendered=\"attempted\"} %" APR_UINT64_T_FMT "\n" , local_stats . noOldRender );
1475- ap_rprintf (r , "modtile_tiles_total{age=\"outdated\",rendered=\"attempted\"} %" APR_UINT64_T_FMT "\n" , local_stats . noVeryOldRender );
1467+ ap_rprintf (r , "modtile_tiles_total{age=\"fresh\",rendered=\"no\"} %" APR_UINT64_T_FMT "\n" , local_stats -> noFreshCache );
1468+ ap_rprintf (r , "modtile_tiles_total{age=\"old\",rendered=\"no\"} %" APR_UINT64_T_FMT "\n" , local_stats -> noOldCache );
1469+ ap_rprintf (r , "modtile_tiles_total{age=\"outdated\",rendered=\"no\"} %" APR_UINT64_T_FMT "\n" , local_stats -> noVeryOldCache );
1470+ ap_rprintf (r , "modtile_tiles_total{age=\"fresh\",rendered=\"yes\"} %" APR_UINT64_T_FMT "\n" , local_stats -> noFreshRender );
1471+ ap_rprintf (r , "modtile_tiles_total{age=\"old\",rendered=\"attempted\"} %" APR_UINT64_T_FMT "\n" , local_stats -> noOldRender );
1472+ ap_rprintf (r , "modtile_tiles_total{age=\"outdated\",rendered=\"attempted\"} %" APR_UINT64_T_FMT "\n" , local_stats -> noVeryOldRender );
14761473
14771474 ap_rprintf (r , "# HELP modtile_zoom_responses_total Tiles served by zoom level\n" );
14781475 ap_rprintf (r , "# TYPE modtile_zoom_responses_total counter\n" );
14791476
14801477 for (i = 0 ; i <= global_max_zoom ; i ++ ) {
1481- ap_rprintf (r , "modtile_zoom_responses_total{zoom=\"%02i\"} %" APR_UINT64_T_FMT "\n" , i , local_stats . noRespZoom [i ]);
1478+ ap_rprintf (r , "modtile_zoom_responses_total{zoom=\"%02i\"} %" APR_UINT64_T_FMT "\n" , i , local_stats -> noRespZoom [i ]);
14821479 }
14831480
14841481 ap_rprintf (r , "# HELP modtile_tile_reads_total Tiles served from the tile buffer\n" );
14851482 ap_rprintf (r , "# TYPE modtile_tile_reads_total counter\n" );
14861483
14871484 for (i = 0 ; i <= global_max_zoom ; i ++ ) {
1488- ap_rprintf (r , "modtile_tile_reads_total{zoom=\"%02i\"} %" APR_UINT64_T_FMT "\n" , i , local_stats . noZoomBufferRetrieval [i ]);
1485+ ap_rprintf (r , "modtile_tile_reads_total{zoom=\"%02i\"} %" APR_UINT64_T_FMT "\n" , i , local_stats -> noZoomBufferRetrieval [i ]);
14891486 }
14901487
14911488 ap_rprintf (r , "# HELP modtile_tile_reads_seconds_total Tile buffer duration\n" );
14921489 ap_rprintf (r , "# TYPE modtile_tile_reads_seconds_total counter\n" );
14931490
14941491 for (i = 0 ; i <= global_max_zoom ; i ++ ) {
1495- ap_rprintf (r , "modtile_tile_reads_seconds_total{zoom=\"%02i\"} %lf\n" , i , (double )local_stats . zoomBufferRetrievalTime [i ] / 1000000.0 );
1492+ ap_rprintf (r , "modtile_tile_reads_seconds_total{zoom=\"%02i\"} %lf\n" , i , (double )local_stats -> zoomBufferRetrievalTime [i ] / 1000000.0 );
14961493 }
14971494
14981495 ap_rprintf (r , "# HELP modtile_layer_responses_total Layer responses\n" );
14991496 ap_rprintf (r , "# TYPE modtile_layer_responses_total counter\n" );
15001497
15011498 for (i = 0 ; i < scfg -> configs -> nelts ; ++ i ) {
15021499 tile_config_rec * tile_config = & tile_configs [i ];
1503- ap_rprintf (r , "modtile_layer_responses_total{layer=\"%s\",status=\"200\"} %" APR_UINT64_T_FMT "\n" , tile_config -> baseuri , local_stats . noResp200Layer [i ]);
1504- ap_rprintf (r , "modtile_layer_responses_total{layer=\"%s\",status=\"404\"} %" APR_UINT64_T_FMT "\n" , tile_config -> baseuri , local_stats . noResp404Layer [i ]);
1500+ ap_rprintf (r , "modtile_layer_responses_total{layer=\"%s\",status=\"200\"} %" APR_UINT64_T_FMT "\n" , tile_config -> baseuri , local_stats -> noResp200Layer [i ]);
1501+ ap_rprintf (r , "modtile_layer_responses_total{layer=\"%s\",status=\"404\"} %" APR_UINT64_T_FMT "\n" , tile_config -> baseuri , local_stats -> noResp404Layer [i ]);
15051502 }
15061503
1507- free (local_stats .noResp200Layer );
1508- free (local_stats .noResp404Layer );
15091504 return OK ;
15101505}
15111506
@@ -1523,13 +1518,13 @@ static int tile_handler_serve(request_rec *r)
15231518 tile_config_rec * tile_configs ;
15241519 struct tile_request_data * rdata ;
15251520 struct protocol * cmd ;
1526-
1527- tile_server_conf * scfg = (tile_server_conf * )ap_get_module_config (r -> server -> module_config , & tile_module );
1521+ tile_server_conf * scfg ;
15281522
15291523 if (strcmp (r -> handler , "tile_serve" )) {
15301524 return DECLINED ;
15311525 }
15321526
1527+ scfg = (tile_server_conf * )ap_get_module_config (r -> server -> module_config , & tile_module );
15331528 rdata = (struct tile_request_data * )ap_get_module_config (r -> request_config , & tile_module );
15341529 cmd = rdata -> cmd ;
15351530
@@ -1559,7 +1554,7 @@ static int tile_handler_serve(request_rec *r)
15591554 gettimeofday (& start , NULL );
15601555
15611556 // FIXME: It is a waste to do the malloc + read if we are fulfilling a HEAD or returning a 304.
1562- buf = (char * )malloc ( tile_max );
1557+ buf = (char * )apr_palloc ( r -> pool , tile_max );
15631558
15641559 if (!buf ) {
15651560 if (!incRespCounter (HTTP_INTERNAL_SERVER_ERROR , r , cmd , rdata -> layerNumber )) {
@@ -1610,8 +1605,6 @@ static int tile_handler_serve(request_rec *r)
16101605 incTimingCounter ((end .tv_sec * 1000000 + end .tv_usec ) - (start .tv_sec * 1000000 + start .tv_usec ), cmd -> z , r );
16111606
16121607 if ((errstatus = ap_meets_conditions (r )) != OK ) {
1613- free (buf );
1614-
16151608 if (!incRespCounter (errstatus , r , cmd , rdata -> layerNumber )) {
16161609 ap_log_rerror (APLOG_MARK , APLOG_WARNING , 0 , r ,
16171610 "Failed to increase response stats counter" );
@@ -1620,7 +1613,6 @@ static int tile_handler_serve(request_rec *r)
16201613 return errstatus ;
16211614 } else {
16221615 ap_rwrite (buf , len , r );
1623- free (buf );
16241616
16251617 if (!incRespCounter (errstatus , r , cmd , rdata -> layerNumber )) {
16261618 ap_log_rerror (APLOG_MARK , APLOG_WARNING , 0 , r ,
@@ -1631,7 +1623,6 @@ static int tile_handler_serve(request_rec *r)
16311623 }
16321624 }
16331625
1634- free (buf );
16351626 ap_log_rerror (APLOG_MARK , APLOG_WARNING , 0 , r , "Failed to read tile from disk: %s" , err_msg );
16361627
16371628 if (!incRespCounter (HTTP_NOT_FOUND , r , cmd , rdata -> layerNumber )) {
0 commit comments