summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2006-10-17 01:18:32 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 14:21:16 -0500
commit6ba4992faabd47bfb77ca3eedc902f9a5e83d24a (patch)
treeb98817c2c625cfa60b7cc268248a489a24ac0e8e
parent1447b7aed93a016f1b762bf1631548aefc7ae2ad (diff)
downloadsamba-6ba4992faabd47bfb77ca3eedc902f9a5e83d24a.tar.gz
samba-6ba4992faabd47bfb77ca3eedc902f9a5e83d24a.tar.bz2
samba-6ba4992faabd47bfb77ca3eedc902f9a5e83d24a.zip
r19360: improve the ldb leak detector - it now takes into account the number
of blocks used at connect time (which depends on how many modules are loaded) (This used to be commit e3aa03bf1f7c7b770606f5e860fce11b4402fc84)
-rw-r--r--source4/lib/db_wrap.c15
1 files changed, 12 insertions, 3 deletions
diff --git a/source4/lib/db_wrap.c b/source4/lib/db_wrap.c
index 2287458543..f884140d1c 100644
--- a/source4/lib/db_wrap.c
+++ b/source4/lib/db_wrap.c
@@ -65,13 +65,16 @@ char *wrap_casefold(void *context, void *mem_ctx, const char *s)
return strupper_talloc(mem_ctx, s);
}
-/* check for leaks */
+/* check for memory leaks on the ldb context */
static int ldb_wrap_destructor(struct ldb_context *ldb)
{
- if (talloc_total_blocks(ldb) > 656) {
- DEBUG(0,("WARNING: probable memory leak in ldb %s - %lu blocks %lu bytes\n",
+ size_t *startup_blocks = (size_t *)ldb_get_opaque(ldb, "startup_blocks");
+ if (startup_blocks &&
+ talloc_total_blocks(ldb) > *startup_blocks + 100) {
+ DEBUG(0,("WARNING: probable memory leak in ldb %s - %lu blocks (startup %lu) %lu bytes\n",
(char *)ldb_get_opaque(ldb, "wrap_url"),
(unsigned long)talloc_total_blocks(ldb),
+ (unsigned long)*startup_blocks,
(unsigned long)talloc_total_size(ldb)));
#if 0
talloc_report_full(ldb, stdout);
@@ -97,6 +100,7 @@ struct ldb_context *ldb_wrap_connect(TALLOC_CTX *mem_ctx,
int ret;
struct event_context *ev;
char *real_url = NULL;
+ size_t *startup_blocks;
ldb = ldb_init(mem_ctx);
if (ldb == NULL) {
@@ -155,7 +159,12 @@ struct ldb_context *ldb_wrap_connect(TALLOC_CTX *mem_ctx,
ldb_set_utf8_fns(ldb, NULL, wrap_casefold);
+ /* setup for leak detection */
ldb_set_opaque(ldb, "wrap_url", real_url);
+ startup_blocks = talloc(ldb, size_t);
+ *startup_blocks = talloc_total_blocks(ldb);
+ ldb_set_opaque(ldb, "startup_blocks", startup_blocks);
+
talloc_set_destructor(ldb, ldb_wrap_destructor);
return ldb;