NXP-15106: properly close stream