summaryrefslogtreecommitdiff
path: root/source3/lib
diff options
context:
space:
mode:
authorJeremy Allison <jra@samba.org>2008-11-06 20:48:13 -0800
committerJeremy Allison <jra@samba.org>2008-11-06 20:48:13 -0800
commit8962be69c700224983af4effd2cd086f7f5800b0 (patch)
treead2149c31ca5102a213a13a75cd511b11c64d812 /source3/lib
parent7ae625345536572aa946f0715542a5cf2dbc2169 (diff)
downloadsamba-8962be69c700224983af4effd2cd086f7f5800b0.tar.gz
samba-8962be69c700224983af4effd2cd086f7f5800b0.tar.bz2
samba-8962be69c700224983af4effd2cd086f7f5800b0.zip
Make us clean under valgrind --leak-check=full by using talloc_autofree_context() instead of NULL.
Remove the code in memcache that does a TALLOC_FREE on stored pointers. That's a disaster waiting to happen. If you're storing talloc'ed pointers, you can't know their lifecycle and they should be deleted when their parent context is deleted, so freeing them at some arbitrary point later will be a double-free. Jeremy.
Diffstat (limited to 'source3/lib')
-rw-r--r--source3/lib/memcache.c26
-rw-r--r--source3/lib/util.c6
-rw-r--r--source3/lib/util_pw.c2
3 files changed, 4 insertions, 30 deletions
diff --git a/source3/lib/memcache.c b/source3/lib/memcache.c
index 9c892fedfa..d586f707fa 100644
--- a/source3/lib/memcache.c
+++ b/source3/lib/memcache.c
@@ -40,37 +40,11 @@ struct memcache {
static void memcache_element_parse(struct memcache_element *e,
DATA_BLOB *key, DATA_BLOB *value);
-static bool memcache_is_talloc(enum memcache_number n)
-{
- bool result;
-
- switch (n) {
- case GETPWNAM_CACHE:
- case PDB_GETPWSID_CACHE:
- case SINGLETON_CACHE_TALLOC:
- result = true;
- break;
- default:
- result = false;
- break;
- }
-
- return result;
-}
-
static int memcache_destructor(struct memcache *cache) {
struct memcache_element *e, *next;
for (e = cache->mru; e != NULL; e = next) {
next = e->next;
- if (memcache_is_talloc((enum memcache_number)e->n)
- && (e->valuelength == sizeof(void *))) {
- DATA_BLOB key, value;
- void *ptr;
- memcache_element_parse(e, &key, &value);
- memcpy(&ptr, value.data, sizeof(ptr));
- TALLOC_FREE(ptr);
- }
SAFE_FREE(e);
}
return 0;
diff --git a/source3/lib/util.c b/source3/lib/util.c
index 820cf376be..5007fb72ef 100644
--- a/source3/lib/util.c
+++ b/source3/lib/util.c
@@ -1497,7 +1497,7 @@ uid_t nametouid(const char *name)
char *p;
uid_t u;
- pass = getpwnam_alloc(NULL, name);
+ pass = getpwnam_alloc(talloc_autofree_context(), name);
if (pass) {
u = pass->pw_uid;
TALLOC_FREE(pass);
@@ -2255,8 +2255,8 @@ char *myhostname(void)
static char *ret;
if (ret == NULL) {
/* This is cached forever so
- * use NULL talloc ctx. */
- ret = talloc_get_myname(NULL);
+ * use talloc_autofree_context() ctx. */
+ ret = talloc_get_myname(talloc_autofree_context());
}
return ret;
}
diff --git a/source3/lib/util_pw.c b/source3/lib/util_pw.c
index c0d37f1094..e0dbc97f00 100644
--- a/source3/lib/util_pw.c
+++ b/source3/lib/util_pw.c
@@ -57,7 +57,7 @@ struct passwd *getpwnam_alloc(TALLOC_CTX *mem_ctx, const char *name)
return NULL;
}
- cached = tcopy_passwd(NULL, temp);
+ cached = tcopy_passwd(talloc_autofree_context(), temp);
if (cached == NULL) {
/*
* Just don't add this into the cache, ignore the failure