sstables: fix bug with debug runs
sstables: fix bug with debug runs

While improving the summary code, the debug build code started to fail, for
apparently no reason. The code being introduced wasn't really doing anything
other than making the execution potentially slightly longer.

Still, the debug run was complaining about an use-after-free, with the
following stack trace in the free side:

freed by thread T1 here:
    #0 0x7f3b1145f64f in operator delete(void*) (/lib64/libasan.so.1+0x5864f)
    #1 0xc615f3 in posix_file_impl::~posix_file_impl() core/file.hh:75
    #2 0x45ae47 in std::default_delete<file_impl>::operator()(file_impl*) const /usr/include/c++/4.9.2/bits/unique_ptr.h:76
    #3 0x442039 in std::unique_ptr<file_impl, std::default_delete<file_impl> >::~unique_ptr() /usr/include/c++/4.9.2/bits/unique_ptr.h:236
    #4 0x438da0 in file::~file() core/file.hh:109
    #5 0x4fd70a in apply core/apply.hh:34
    #6 0x4fd821 in apply<sstables::sstable::read_toc()::<lambda(file)>, file> core/apply.hh:42
    #7 0x4fd91f in apply<sstables::sstable::read_toc()::<lambda(file)>, file> core/future.hh:685

After staring at the code for a while, my main diagnosis was that while in most
of the sstable reading functions we move the file object inside a stream
reader, we don't do that in the TOC. The file is just there and can be freed
after the future that contains it returns, which wasn't happening so far, but can
happen depending on the timing involved.

The following patch moves the file inside the lambda of the following future,
making sure it is not destroyed while the file is still being read. It fixes
the problem with the debug build in my tree.

Signed-off-by: Glauber Costa <f8b79557d19b40666ebe336545a0b6178af65685@cloudius-systems.com>

respu/scylla,linearregression/scylla,avikivity/scylla,justintung/scylla,duarten/scylla,tempbottle/scylla,stamhe/scylla,scylladb/scylla,kangkot/scylla,guiquanz/scylla,glommer/scylla,rluta/scylla,kjniemi/scylla,kangkot/scylla,stamhe/scylla,stamhe/scylla,gwicke/scylla,gwicke/scylla,capturePointer/scylla,asias/scylla,victorbriz/scylla,shaunstanislaus/scylla,wildinto/scylla,kjniemi/scylla,victorbriz/scylla,senseb/scylla,asias/scylla,acbellini/scylla,scylladb/scylla,dwdm/scylla,dwdm/scylla,guiquanz/scylla,duarten/scylla,rluta/scylla,duarten/scylla,linearregression/scylla,tempbottle/scylla,raphaelsc/scylla,aruanruan/scylla,rluta/scylla,eklitzke/scylla,guiquanz/scylla,victorbriz/scylla,wildinto/scylla,respu/scylla,scylladb/scylla,phonkee/scylla,rentongzhang/scylla,acbellini/scylla,tempbottle/scylla,acbellini/scylla,shaunstanislaus/scylla,aruanruan/scylla,senseb/scylla,respu/scylla,shaunstanislaus/scylla,rentongzhang/scylla,justintung/scylla,eklitzke/scylla,linearregression/scylla,scylladb/scylla,avikivity/scylla,bowlofstew/scylla,phonkee/scylla,raphaelsc/scylla,avikivity/scylla,phonkee/scylla,kangkot/scylla,raphaelsc/scylla,asias/scylla,glommer/scylla,bowlofstew/scylla,justintung/scylla,dwdm/scylla,capturePointer/scylla,senseb/scylla,aruanruan/scylla,capturePointer/scylla,rentongzhang/scylla,gwicke/scylla,glommer/scylla,bowlofstew/scylla,eklitzke/scylla,kjniemi/scylla,wildinto/scylla