From fb3835846ef89a632230ff808259dad1cddc05c0 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Mon, 2 Apr 2007 03:46:13 +0000 Subject: r22020: Make it more clear that both the vuser struct and it's contents are talloc_free()'ed at the end of a session. Rework the passwd cache code to use talloc_unlink and talloc_reference, to more carefully manage the cache. Andrew Bartlett (This used to be commit e3e0ec25e67308de314aa61852905ee42aa2c8fe) --- source3/lib/util_pw.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'source3/lib/util_pw.c') diff --git a/source3/lib/util_pw.c b/source3/lib/util_pw.c index dc184233a6..8b3c78a3f9 100644 --- a/source3/lib/util_pw.c +++ b/source3/lib/util_pw.c @@ -98,15 +98,15 @@ struct passwd *getpwnam_alloc(TALLOC_CTX *mem_ctx, const char *name) i = rand() % PWNAMCACHE_SIZE; if (pwnam_cache[i] != NULL) { - TALLOC_FREE(pwnam_cache[i]); + /* Remove this old cache entry, from the cache. We + * use talloc_unlink here because we want to be very + * clear which referece we are removing */ + talloc_unlink(pwnam_cache, pwnam_cache[i]); } pwnam_cache[i] = tcopy_passwd(pwnam_cache, temp); - if (pwnam_cache[i]!= NULL && mem_ctx != NULL) { - return (struct passwd *)talloc_reference(mem_ctx, pwnam_cache[i]); - } - - return tcopy_passwd(NULL, pwnam_cache[i]); + /* while keeping this in the cache, reference a copy for the caller */ + return (struct passwd *)talloc_reference(mem_ctx, pwnam_cache[i]); } struct passwd *getpwuid_alloc(TALLOC_CTX *mem_ctx, uid_t uid) -- cgit