lib/flash: fix resource leak in flash_setup_buffer() error paths