From 44707ad2e00a91f459e80efbe8f362b5853b0a62 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Mon, 29 Aug 2005 14:55:40 +0000 Subject: r9739: conver the reg_objects (REGSUBKEY_CTR & REGVAL_CTR) to use the new talloc() features: Note that the REGSUB_CTR and REGVAL_CTR objects *must* be talloc()'d since the methods use the object pointer as the talloc context for internal private data. There is no longer a regXXX_ctr_intit() and regXXX_ctr_destroy() pair of functions. Simply TALLOC_ZERO_P() and TALLOC_FREE() the object. Also had to convert the printer_info_2->NT_PRINTER_DATA field to be talloc()'d as well. This is just a stop on the road to cleaning up the printer memory management. (This used to be commit ef721333ab9639cb5346067497e99fbd0d4425dd) --- source3/registry/reg_frontend.c | 58 +++++++++++++++++++++++++---------------- 1 file changed, 35 insertions(+), 23 deletions(-) (limited to 'source3/registry/reg_frontend.c') diff --git a/source3/registry/reg_frontend.c b/source3/registry/reg_frontend.c index 51ad23b498..d6e0288461 100644 --- a/source3/registry/reg_frontend.c +++ b/source3/registry/reg_frontend.c @@ -38,7 +38,9 @@ REGISTRY_HOOK reg_hooks[] = { { KEY_PRINTING, &printing_ops }, { KEY_PRINTING_2K, &printing_ops }, { KEY_PRINTING_PORTS, &printing_ops }, +#if 0 { KEY_EVENTLOG, &eventlog_ops }, +#endif { KEY_SHARES, &shares_reg_ops }, #endif { NULL, NULL } @@ -124,9 +126,8 @@ int fetch_reg_keys( REGISTRY_KEY *key, REGSUBKEY_CTR *subkey_ctr ) BOOL fetch_reg_keys_specific( REGISTRY_KEY *key, char** subkey, uint32 key_index ) { - static REGSUBKEY_CTR ctr; + static REGSUBKEY_CTR *ctr = NULL; static pstring save_path; - static BOOL ctr_init = False; char *s; *subkey = NULL; @@ -135,32 +136,39 @@ BOOL fetch_reg_keys_specific( REGISTRY_KEY *key, char** subkey, uint32 key_index DEBUG(8,("fetch_reg_keys_specific: Looking for key [%d] of [%s]\n", key_index, key->name)); - if ( !ctr_init ) { + if ( !ctr ) { DEBUG(8,("fetch_reg_keys_specific: Initializing cache of subkeys for [%s]\n", key->name)); - regsubkey_ctr_init( &ctr ); + + if ( !(ctr = TALLOC_ZERO_P( NULL, REGSUBKEY_CTR )) ) { + DEBUG(0,("fetch_reg_keys_specific: talloc() failed!\n")); + return False; + } pstrcpy( save_path, key->name ); - if ( fetch_reg_keys( key, &ctr) == -1 ) + if ( fetch_reg_keys( key, ctr) == -1 ) return False; - ctr_init = True; } /* clear the cache when key_index == 0 or the path has changed */ else if ( !key_index || StrCaseCmp( save_path, key->name) ) { DEBUG(8,("fetch_reg_keys_specific: Updating cache of subkeys for [%s]\n", key->name)); - regsubkey_ctr_destroy( &ctr ); - regsubkey_ctr_init( &ctr ); + TALLOC_FREE( ctr ); + + if ( !(ctr = TALLOC_ZERO_P( NULL, REGSUBKEY_CTR )) ) { + DEBUG(0,("fetch_reg_keys_specific: talloc() failed!\n")); + return False; + } pstrcpy( save_path, key->name ); - if ( fetch_reg_keys( key, &ctr) == -1 ) + if ( fetch_reg_keys( key, ctr) == -1 ) return False; } - if ( !(s = regsubkey_ctr_specific_key( &ctr, key_index )) ) + if ( !(s = regsubkey_ctr_specific_key( ctr, key_index )) ) return False; *subkey = SMB_STRDUP( s ); @@ -198,42 +206,46 @@ int fetch_reg_values( REGISTRY_KEY *key, REGVAL_CTR *val ) BOOL fetch_reg_values_specific( REGISTRY_KEY *key, REGISTRY_VALUE **val, uint32 val_index ) { - static REGVAL_CTR ctr; + static REGVAL_CTR *ctr = NULL; static pstring save_path; - static BOOL ctr_init = False; REGISTRY_VALUE *v; *val = NULL; /* simple caching for performance; very basic heuristic */ - if ( !ctr_init ) { + if ( !ctr ) { DEBUG(8,("fetch_reg_values_specific: Initializing cache of values for [%s]\n", key->name)); - regval_ctr_init( &ctr ); - + if ( !(ctr = TALLOC_ZERO_P( NULL, REGVAL_CTR )) ) { + DEBUG(0,("fetch_reg_values_specific: talloc() failed!\n")); + return False; + } + pstrcpy( save_path, key->name ); - if ( fetch_reg_values( key, &ctr) == -1 ) + if ( fetch_reg_values( key, ctr) == -1 ) return False; - - ctr_init = True; } /* clear the cache when val_index == 0 or the path has changed */ else if ( !val_index || !strequal(save_path, key->name) ) { DEBUG(8,("fetch_reg_values_specific: Updating cache of values for [%s]\n", key->name)); - regval_ctr_destroy( &ctr ); - regval_ctr_init( &ctr ); - + TALLOC_FREE( ctr ); + + if ( !(ctr = TALLOC_ZERO_P( NULL, REGVAL_CTR )) ) { + DEBUG(0,("fetch_reg_values_specific: talloc() failed!\n")); + return False; + } + pstrcpy( save_path, key->name ); - if ( fetch_reg_values( key, &ctr) == -1 ) + if ( fetch_reg_values( key, ctr) == -1 ) return False; } - if ( !(v = regval_ctr_specific_value( &ctr, val_index )) ) + if ( !(v = regval_ctr_specific_value( ctr, val_index )) ) return False; *val = dup_registry_value( v ); -- cgit