diff options
Diffstat (limited to 'source3/lib')
-rw-r--r-- | source3/lib/util_pw.c | 12 |
1 files changed, 6 insertions, 6 deletions
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) |