database: fix potential use-after-free in sstable cleanup
database: fix potential use-after-free in sstable cleanup

when do_for_each is in its last iteration and with_semaphore defers
because there's an ongoing cleanup, sstable object will be used after
freed because it was taken by ref and the container it lives in was
destroyed prematurely.

Let's fix it with a do_with, also making code nicer.

Fixes #2537.

Signed-off-by: Raphael S. Carvalho <1e2942cea40e3b4d2162dfcd9e53e41c05a84d22@scylladb.com>
Message-Id: <20170630035324.19881-1-1e2942cea40e3b4d2162dfcd9e53e41c05a84d22@scylladb.com>

avikivity/scylla,duarten/scylla,scylladb/scylla,scylladb/scylla,duarten/scylla,duarten/scylla,avikivity/scylla,scylladb/scylla,scylladb/scylla,avikivity/scylla