@@ -797,15 +797,6 @@ static const char* oidc_set_session_max_duration(cmd_parms *cmd,
797797 return OIDC_CONFIG_DIR_RV (cmd , rv );
798798}
799799
800- static apr_status_t oidc_cleanup_keys (void * data ) {
801- apr_array_header_t * keys_list = (apr_array_header_t * ) data ;
802- oidc_jwk_t * * jwk = NULL ;
803- while ((jwk = apr_array_pop (keys_list ))) {
804- oidc_jwk_destroy (* jwk );
805- }
806- return APR_SUCCESS ;
807- }
808-
809800/*
810801 * add a public key from an X.509 file to our list of JWKs with public keys
811802 */
@@ -837,11 +828,8 @@ static const char* oidc_set_public_key_files(cmd_parms *cmd, void *struct_ptr,
837828 kid , fname , oidc_jose_e2s (cmd -> pool , err ));
838829 }
839830
840- if (* public_keys == NULL ) {
831+ if (* public_keys == NULL )
841832 * public_keys = apr_array_make (cmd -> pool , 4 , sizeof (const oidc_jwk_t * ));
842- apr_pool_cleanup_register (cmd -> pool , * public_keys , oidc_cleanup_keys ,
843- oidc_cleanup_keys );
844- }
845833
846834 * (const oidc_jwk_t * * ) apr_array_push (* public_keys ) = jwk ;
847835
@@ -910,12 +898,9 @@ static const char* oidc_set_private_key_files_enc(cmd_parms *cmd, void *dummy,
910898 kid , fname , oidc_jose_e2s (cmd -> pool , err ));
911899 }
912900
913- if (cfg -> private_keys == NULL ) {
901+ if (cfg -> private_keys == NULL )
914902 cfg -> private_keys = apr_array_make (cmd -> pool , 4 ,
915903 sizeof (const oidc_jwk_t * ));
916- apr_pool_cleanup_register (cmd -> pool , cfg -> private_keys ,
917- oidc_cleanup_keys , oidc_cleanup_keys );
918- }
919904
920905 * (const oidc_jwk_t * * ) apr_array_push (cfg -> private_keys ) = jwk ;
921906
@@ -1468,11 +1453,26 @@ void oidc_cfg_provider_init(oidc_provider_t *provider) {
14681453 provider -> auth_request_method = OIDC_DEFAULT_AUTH_REQUEST_METHOD ;
14691454}
14701455
1456+ static apr_status_t oidc_destroy_server_config (void * data ) {
1457+ oidc_cfg * cfg = (oidc_cfg * )data ;
1458+ // can do this even though we haven't got a deep copy
1459+ // since references within the oidc_jwk_t object will be set to NULL
1460+ if (cfg -> provider .jwks_uri .jwk )
1461+ oidc_jwk_destroy (cfg -> provider .jwks_uri .jwk );
1462+ oidc_jwk_list_destroy (cfg -> provider .verify_public_keys );
1463+ oidc_jwk_list_destroy (cfg -> oauth .verify_public_keys );
1464+ oidc_jwk_list_destroy_hash (cfg -> oauth .verify_shared_keys );
1465+ oidc_jwk_list_destroy (cfg -> public_keys );
1466+ oidc_jwk_list_destroy (cfg -> private_keys );
1467+ return APR_SUCCESS ;
1468+ }
1469+
14711470/*
14721471 * create a new server config record with defaults
14731472 */
14741473void * oidc_create_server_config (apr_pool_t * pool , server_rec * svr ) {
14751474 oidc_cfg * c = apr_pcalloc (pool , sizeof (oidc_cfg ));
1475+ apr_pool_cleanup_register (pool , c , oidc_destroy_server_config , oidc_destroy_server_config );
14761476
14771477 c -> merged = FALSE;
14781478
@@ -1603,6 +1603,7 @@ void* oidc_create_server_config(apr_pool_t *pool, server_rec *svr) {
16031603 */
16041604void * oidc_merge_server_config (apr_pool_t * pool , void * BASE , void * ADD ) {
16051605 oidc_cfg * c = apr_pcalloc (pool , sizeof (oidc_cfg ));
1606+ apr_pool_cleanup_register (pool , c , oidc_destroy_server_config , oidc_destroy_server_config );
16061607 oidc_cfg * base = BASE ;
16071608 oidc_cfg * add = ADD ;
16081609
@@ -2705,20 +2706,6 @@ static apr_status_t oidc_cleanup_child(void *data) {
27052706 oidc_serror (sp , "cache destroy function failed" );
27062707 }
27072708 }
2708-
2709- // can do this even though we haven't got a deep copy
2710- // since references within the oidc_jwk_t object will be set to NULL
2711- if (cfg -> provider .jwks_uri .jwk )
2712- oidc_jwk_destroy (cfg -> provider .jwks_uri .jwk );
2713- oidc_jwk_list_destroy (sp -> process -> pool ,
2714- cfg -> provider .verify_public_keys );
2715- oidc_jwk_list_destroy (sp -> process -> pool ,
2716- cfg -> oauth .verify_public_keys );
2717- oidc_jwk_list_destroy_hash (sp -> process -> pool ,
2718- cfg -> oauth .verify_shared_keys );
2719- oidc_jwk_list_destroy (sp -> process -> pool , cfg -> public_keys );
2720- oidc_jwk_list_destroy (sp -> process -> pool , cfg -> private_keys );
2721-
27222709 sp = sp -> next ;
27232710 }
27242711
0 commit comments