row_cache: fix memory leak in case of schema upgrade failure

When update() causes a new entry to be inserted to the cache the
procedure is as follows:
1. allocate and construct new entry
2. upgrade entry schema
3. add entry to lru list and cache tree

Step 2 may fail and at this point the pointer to the entry is neither
protected by RAII nor added in any of the cache containers. The solution
is to swap steps 2 and 3 so that even if the upgrade fails the entry is
already owned by the cache and won't leak.

Signed-off-by: Paweł Dziepak <pdziepak@scylladb.com>
Message-Id: <1466161709-25288-1-git-send-email-pdziepak@scylladb.com>
This commit is contained in:
Paweł Dziepak
2016-06-17 12:08:29 +01:00
committed by Tomasz Grabiec
parent 4659800ab9
commit daad2ebf81

View File

@@ -548,9 +548,9 @@ future<> row_cache::update(memtable& m, partition_presence_checker presence_chec
partition_presence_checker_result::definitely_doesnt_exist) {
cache_entry* entry = current_allocator().construct<cache_entry>(
mem_e.schema(), std::move(mem_e.key()), std::move(mem_e.partition()));
upgrade_entry(*entry);
_tracker.insert(*entry);
_partitions.insert(cache_i, *entry);
upgrade_entry(*entry);
}
i = m.partitions.erase(i);
current_allocator().destroy(&mem_e);