Fixes file descriptor leak in random_read