aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/c/urweb.c
diff options
context:
space:
mode:
authorGravatar Adam Chlipala <adam@chlipala.net>2015-11-19 13:18:58 -0500
committerGravatar Adam Chlipala <adam@chlipala.net>2015-11-19 13:18:58 -0500
commit30dd885d1fc3013be0e3c2a45b2e0117f684f40a (patch)
tree6a4c70334b35d4b065a6b8fa81842fb1cc45adcb /src/c/urweb.c
parent7a49a90f8b092e1c2e58d3e754578cff3bf06b18 (diff)
Fix a read-after-free bug using a timestamp check
Diffstat (limited to 'src/c/urweb.c')
-rw-r--r--src/c/urweb.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/src/c/urweb.c b/src/c/urweb.c
index 945a6890..093a5294 100644
--- a/src/c/urweb.c
+++ b/src/c/urweb.c
@@ -4720,9 +4720,11 @@ static void uw_Sqlcache_storeCommitOne(uw_Sqlcache_Cache *cache, char **keys, uw
}
free(key);
}
- uw_Sqlcache_freeValue(entry->value);
- entry->value = value;
- entry->value->timeValid = timeNow;
+ if (entry->value && entry->value->timeValid < value->timeValid) {
+ uw_Sqlcache_freeValue(entry->value);
+ entry->value = value;
+ entry->value->timeValid = timeNow;
+ }
pthread_rwlock_unlock(&cache->lockIn);
}
@@ -4807,6 +4809,7 @@ void uw_Sqlcache_store(uw_context ctx, uw_Sqlcache_Cache *cache, char **keys, uw
update->keys = uw_Sqlcache_copyKeys(keys, cache->numKeys);
update->value = value;
update->next = NULL;
+ value->timeValid = uw_Sqlcache_getTimeNow(cache);
if (ctx->cacheUpdateTail) {
ctx->cacheUpdateTail->next = update;
} else {