Return existsing cache_tree if it has already been initialized.
authorMichael Adam <obnox@samba.org>
Thu, 3 Jan 2008 11:07:02 +0000 (12:07 +0100)
committerMichael Adam <obnox@samba.org>
Thu, 3 Jan 2008 11:07:02 +0000 (12:07 +0100)
So reghook_cache_init() does not leak memory when called more
than once.
Also, fix the return value while we are at it.

Michael
(This used to be commit 25f571f40a630bff5a47bba6b01e42d4e0ffed66)

source3/registry/reg_cachehook.c

index 289d4e50cec788bfbc7d758d328ea31c73459808..74670aac30ec211c9b50bd1646cf3cdcc3fa2725 100644 (file)
 #undef DBGC_CLASS
 #define DBGC_CLASS DBGC_REGISTRY
 
-static SORTED_TREE *cache_tree;
+static SORTED_TREE *cache_tree = NULL;
 extern REGISTRY_OPS regdb_ops;         /* these are the default */
 static REGISTRY_HOOK default_hook = { KEY_TREE_ROOT, &regdb_ops };
 
 /**********************************************************************
- Initialize the cache tree
+ Initialize the cache tree if it has not been initialized yet.
  *********************************************************************/
 
 bool reghook_cache_init( void )
 {
-       cache_tree = pathtree_init( &default_hook, NULL );
+       if (cache_tree == NULL) {
+               cache_tree = pathtree_init(&default_hook, NULL);
+       }
 
-       return ( cache_tree == NULL );
+       return (cache_tree != NULL);
 }
 
 /**********************************************************************