ldap/servers/slapd/back-ldbm/cache.c | 19 ++++++++++++++++---
1 file changed, 16 insertions(+), 3 deletions(-)
New commits:
commit fe9b6a6bab32353f55a6ce2123f7df6b72a9a5a7
Author: Noriko Hosoi <nhosoi(a)redhat.com>
Date: Tue Apr 19 12:17:49 2011 -0700
Bug 697027 - 3 - minor memory leaks found by Valgrind + TET
https://bugzilla.redhat.com/show_bug.cgi?id=697027
Description: Adding slapi_counter_destroy to destroy counters
cache->c_cursize, c_hits, and c_tries used in the entry cache.
Additionally, changing to make cache_init fail if slapi_counter
is not enabled since cache->c_cursize depends upon the counter
and the cache module cannot function unless c_cursize is available.
diff --git a/ldap/servers/slapd/back-ldbm/cache.c b/ldap/servers/slapd/back-ldbm/cache.c
index e29247e..95fa638 100644
--- a/ldap/servers/slapd/back-ldbm/cache.c
+++ b/ldap/servers/slapd/back-ldbm/cache.c
@@ -519,14 +519,24 @@ int cache_init(struct cache *cache, size_t maxsize, long maxentries,
int type)
LDAPDebug(LDAP_DEBUG_TRACE, "=> cache_init\n", 0, 0, 0);
cache->c_maxsize = maxsize;
cache->c_maxentries = maxentries;
- cache->c_cursize = slapi_counter_new();
cache->c_curentries = 0;
if (config_get_slapi_counters()) {
+ if (cache->c_cursize) {
+ slapi_counter_destroy(&cache->c_cursize);
+ }
+ cache->c_cursize = slapi_counter_new();
+ if (cache->c_hits) {
+ slapi_counter_destroy(&cache->c_hits);
+ }
cache->c_hits = slapi_counter_new();
+ if (cache->c_tries) {
+ slapi_counter_destroy(&cache->c_tries);
+ }
cache->c_tries = slapi_counter_new();
} else {
- cache->c_hits = NULL;
- cache->c_tries = NULL;
+ LDAPDebug0Args(LDAP_DEBUG_ANY,
+ "cache_init: slapi counter is not available.\n");
+ return 0;
}
cache->c_lruhead = cache->c_lrutail = NULL;
cache_make_hashes(cache, type);
@@ -651,6 +661,9 @@ static void erase_cache(struct cache *cache, int type)
void cache_destroy_please(struct cache *cache, int type)
{
erase_cache(cache, type);
+ slapi_counter_destroy(&cache->c_cursize);
+ slapi_counter_destroy(&cache->c_hits);
+ slapi_counter_destroy(&cache->c_tries);
PR_DestroyLock(cache->c_mutex);
PR_DestroyLock(cache->c_emutexalloc_mutex);
}