Fix #516. Close WAL log/index files if they aren't needed anymore