Skip to content

Commit 3aad8fb

Browse files
[BP] Update FileMgr's KvHeader only within FileMgr's spin lock context
This is to avoid racing in setting KvHeader which could potentially cause leaks. 11:58:40 Direct leak of 56 byte(s) in 1 object(s) allocated from: 11:58:40 #0 0x4eead2 in operator new(unsigned long) (/home/couchbase/jenkins/workspace/forestdb-address_sanitizer-unstable/build/forestdb/tests/usecase/usecase_test+0x4eead2) 11:58:40 #1 0x5db423 in _fdb_kvs_header_create /home/couchbase/jenkins/workspace/forestdb-address_sanitizer-unstable/forestdb/src/kv_instance.cc:282:28 11:58:40 #2 0x599fb4 in FdbEngine::openFdb(FdbKvsHandle*, char const*, fdb_filename_mode_t, fdb_config const*) /home/couchbase/jenkins/workspace/forestdb-address_sanitizer-unstable/forestdb/src/forestdb.cc:2302:25 11:58:40 #3 0x5a582b in fdb_check_file_reopen /home/couchbase/jenkins/workspace/forestdb-address_sanitizer-unstable/forestdb/src/forestdb.cc:1175:18 11:58:40 #4 0x5aa1dc in FdbEngine::set(FdbKvsHandle*, fdb_doc_struct*) /home/couchbase/jenkins/workspace/forestdb-address_sanitizer-unstable/forestdb/src/forestdb.cc:3341:10 11:58:40 #5 0x506741 in FdbEngine::setKeyValue(FdbKvsHandle*, void const*, unsigned long, void const*, unsigned long) /home/couchbase/jenkins/workspace/forestdb-address_sanitizer-unstable/forestdb/src/api_wrapper.cc:165:10 11:58:40 #6 0x4f6acd in test_writes_on_kv_stores_with_compaction(unsigned short, int) /home/couchbase/jenkins/workspace/forestdb-address_sanitizer-unstable/forestdb/tests/usecase/usecase_test.cc:988:22 11:58:40 #7 0x4fc60a in main /home/couchbase/jenkins/workspace/forestdb-address_sanitizer-unstable/forestdb/tests/usecase/usecase_test.cc:1262:5 11:58:40 #8 0x2b3f217b376c in __libc_start_main /build/buildd/eglibc-2.15/csu/libc-start.c:226 (Reviewed-on: http://review.couchbase.org/67078) Change-Id: Ic23d15d8e95bfea5945fe3c4a3051bc491f21820 Reviewed-on: http://review.couchbase.org/67173 Reviewed-by: Chiyoung Seo <[email protected]> Tested-by: buildbot <[email protected]>
1 parent c676734 commit 3aad8fb

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/kv_instance.cc

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,14 +287,17 @@ void _fdb_kvs_header_create(KvsHeader **kv_header_ptr)
287287

288288
void fdb_kvs_header_create(FileMgr *file)
289289
{
290+
file->acquireSpinLock();
290291
KvsHeader *kv_header = file->getKVHeader_UNLOCKED();
291292
if (kv_header) {
292-
return; // already exist
293+
file->releaseSpinLock();
294+
return; // already exists
293295
}
294296

295297
_fdb_kvs_header_create(&kv_header);
296298
file->setKVHeader_UNLOCKED(kv_header);
297299
file->setFreeKVHeaderCB(fdb_kvs_header_free);
300+
file->releaseSpinLock();
298301
}
299302

300303
void fdb_kvs_header_reset_all_stats(FileMgr *file)
@@ -956,12 +959,15 @@ void _fdb_kvs_header_free(KvsHeader *kv_header)
956959

957960
void fdb_kvs_header_free(FileMgr *file)
958961
{
962+
file->acquireSpinLock();
959963
if (file->getKVHeader_UNLOCKED() == NULL) {
964+
file->releaseSpinLock();
960965
return;
961966
}
962967

963968
_fdb_kvs_header_free(file->getKVHeader_UNLOCKED());
964969
file->setKVHeader_UNLOCKED(NULL);
970+
file->releaseSpinLock();
965971
}
966972

967973
// this function just returns pointer

0 commit comments

Comments
 (0)