From 8e34363f0e6859525506f435ec657259871f281f Mon Sep 17 00:00:00 2001 From: Michael Vrable Date: Wed, 2 Feb 2011 16:07:58 -0800 Subject: [PATCH] Fix a potential race between creating and destroying mmaped strings Potentially, we might try to create a new reference to a memory-mapped region while another thread unreferences and frees that region. Ensure when freeing the mapping that there really are no mappings (doube-check after taking the lock). --- bluesky/log.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bluesky/log.c b/bluesky/log.c index 5a16238..984cf16 100644 --- a/bluesky/log.c +++ b/bluesky/log.c @@ -751,7 +751,7 @@ void bluesky_mmap_unref(BlueSkyCacheFile *mmap) if (g_atomic_int_dec_and_test(&mmap->mapcount)) { g_mutex_lock(mmap->lock); - if (mmap->addr != NULL) { + if (mmap->addr != NULL && g_atomic_int_get(&mmap->mapcount) == 0) { if (bluesky_verbose) g_print("Unmapped log segment %d...\n", mmap->log_seq); munmap((void *)mmap->addr, mmap->len); -- 2.20.1