From eab60e2bb13e0197f3771ab6d60da48a72fb311d Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sat, 9 Sep 2006 21:40:47 +0000 Subject: [PATCH] r18312: Change gencache_get slightly: Delete expired keys, and only strdup the value if a valid entry was found. The newer calls got the latter one wrong, change the older calls. Volker (This used to be commit 554e68887bc84510690226c9b07a872e7a282abe) --- source3/lib/gencache.c | 11 ++++++++++- source3/libsmb/namecache.c | 4 ---- source3/libsmb/trustdom_cache.c | 1 - 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/source3/lib/gencache.c b/source3/lib/gencache.c index 871d1d1d802..dc5f32d66ea 100644 --- a/source3/lib/gencache.c +++ b/source3/lib/gencache.c @@ -212,6 +212,15 @@ BOOL gencache_get(const char *keystr, char **valstr, time_t *timeout) "timeout = %s", t > time(NULL) ? "valid" : "expired", keystr, endptr+1, ctime(&t))); + if (t <= time(NULL)) { + + /* We're expired, delete the entry */ + tdb_delete(cache, keybuf); + + SAFE_FREE(databuf.dptr); + return False; + } + if (valstr) { *valstr = SMB_STRDUP(endptr+1); if (*valstr == NULL) { @@ -227,7 +236,7 @@ BOOL gencache_get(const char *keystr, char **valstr, time_t *timeout) *timeout = t; } - return t > time(NULL); + return True; } diff --git a/source3/libsmb/namecache.c b/source3/libsmb/namecache.c index afbd807198f..bd4b3caeb7d 100644 --- a/source3/libsmb/namecache.c +++ b/source3/libsmb/namecache.c @@ -201,9 +201,7 @@ BOOL namecache_fetch(const char *name, int name_type, struct ip_service **ip_lis if (!gencache_get(key, &value, &timeout)) { DEBUG(5, ("no entry for %s#%02X found.\n", name, name_type)); - gencache_del(key); SAFE_FREE(key); - SAFE_FREE(value); return False; } else { DEBUG(5, ("name %s#%02X found.\n", name, name_type)); @@ -314,9 +312,7 @@ BOOL namecache_status_fetch(const char *keyname, int keyname_type, if (!gencache_get(key, &value, &timeout)) { DEBUG(5, ("namecache_status_fetch: no entry for %s found.\n", key)); - gencache_del(key); SAFE_FREE(key); - SAFE_FREE(value); return False; } else { DEBUG(5, ("namecache_status_fetch: key %s -> %s\n", key, value )); diff --git a/source3/libsmb/trustdom_cache.c b/source3/libsmb/trustdom_cache.c index 8c5fb4d9071..fa35f8d4230 100644 --- a/source3/libsmb/trustdom_cache.c +++ b/source3/libsmb/trustdom_cache.c @@ -183,7 +183,6 @@ BOOL trustdom_cache_fetch(const char* name, DOM_SID* sid) if (!gencache_get(key, &value, &timeout)) { DEBUG(5, ("no entry for trusted domain %s found.\n", name)); SAFE_FREE(key); - SAFE_FREE(value); return False; } else { SAFE_FREE(key); -- 2.11.4.GIT