add fix_free_writebuf() error handling