Fixed: thread corrupted when flush() fails