Purge buffered data when fflush() doesn't work

Change-Id: I49d7bbffaf43e50ab19a3c7be7df067b352cefce