comparison src/lstream.c @ 207:e45d5e7c476e r20-4b2

Import from CVS: tag r20-4b2
author cvs
date Mon, 13 Aug 2007 10:03:52 +0200
parents 3d6bfa290dbd
children 262b8bb4a523
comparison
equal deleted inserted replaced
206:d3e9274cbc4e 207:e45d5e7c476e
712 { 712 {
713 int rc = 0; 713 int rc = 0;
714 714
715 if (lstr->flags & LSTREAM_FL_IS_OPEN) 715 if (lstr->flags & LSTREAM_FL_IS_OPEN)
716 { 716 {
717 /* don't return here on error, or file descriptor leak will result. */
718 rc = Lstream_pseudo_close (lstr); 717 rc = Lstream_pseudo_close (lstr);
718 /*
719 * We used to return immediately if the closer method reported
720 * failure, leaving the stream open. But this is no good, for
721 * the following reasons.
722 *
723 * 1. The finalizer method used in GC makes no provision for
724 * failure, so we must not return without freeing buffer
725 * memory.
726 *
727 * 2. The closer method may have already freed some memory
728 * used for I/O in this stream. E.g. encoding_closer frees
729 * ENCODING_STREAM_DATA(stream)->runoff. If a writer method
730 * tries to use this buffer later, it will write into memory
731 * that may have been allocated elsewhere. Sometime later
732 * you will see a sign that says "Welcome to Crash City."
733 *
734 * 3. The closer can report failure if a flush fails in the
735 * other stream in a MULE encoding/decoding stream pair.
736 * The other stream in the pair is closed, but returning
737 * early leaves the current stream open. If we try to
738 * flush the current stream later, we will crash when the
739 * flusher notices that the other end stream is closed.
740 *
741 * So, we no longer abort the close if the closer method
742 * reports some kind of failure. We still report the failure
743 * to the caller.
744 */
719 if (lstr->imp->closer) 745 if (lstr->imp->closer)
720 { 746 if ((lstr->imp->closer) (lstr) < 0)
721 if ((lstr->imp->closer) (lstr) < 0) 747 rc = -1;
722 return -1;
723 }
724 } 748 }
725 749
726 lstr->flags &= ~LSTREAM_FL_IS_OPEN; 750 lstr->flags &= ~LSTREAM_FL_IS_OPEN;
727 lstr->byte_count = 0; 751 lstr->byte_count = 0;
728 /* Note that Lstream_flush() reset all the buffer indices. That way, 752 /* Note that Lstream_flush() reset all the buffer indices. That way,