Close streams properly

Change-Id: Icfbecc1c2dd7537e899f95018acd1807ff4f82b9
Reviewed-on: http://review.couchbase.org/34333
Reviewed-by: Sarath Lakshman <sarath@couchbase.com>
Tested-by: buildbot <build@couchbase.com>