Fix double close of file descriptor on error. (#82139, Wayne Schuller)

Mon May 20 15:35:59 2002  Owen Taylor  <otaylor@redhat.com>

        * glib/gfileutils.c (get_contents_regfile): Fix double
        close of file descriptor on error. (#82139, Wayne Schuller)

        * glib/gspawn.c (close_and_invalidate): Don't close
        fd's that have already been closed. (Fix from Michael
        Meeks, #81959)

        * glib/giochannel.c (g_io_channel_close): If not flushing,
        dump the contents of the write buffers, so we won't try
        to write them to an invalid fd later. (Patch from Ron Steinke,
        fixing #78290, Andreas Persenius.)
This commit is contained in:
Owen Taylor 2002-05-20 19:36:58 +00:00 committed by Owen Taylor
parent 60f59976d9
commit 81ad1bb215
10 changed files with 127 additions and 18 deletions

View File

@ -1,3 +1,17 @@
Mon May 20 15:35:59 2002 Owen Taylor <otaylor@redhat.com>
* glib/gfileutils.c (get_contents_regfile): Fix double
close of file descriptor on error. (#82139, Wayne Schuller)
* glib/gspawn.c (close_and_invalidate): Don't close
fd's that have already been closed. (Fix from Michael
Meeks, #81959)
* glib/giochannel.c (g_io_channel_close): If not flushing,
dump the contents of the write buffers, so we won't try
to write them to an invalid fd later. (Patch from Ron Steinke,
fixing #78290, Andreas Persenius.)
2002-05-18 Matthias Clasen <maclas@gmx.de>
* tests/markups/fail-36.gmarkup:

View File

@ -1,3 +1,17 @@
Mon May 20 15:35:59 2002 Owen Taylor <otaylor@redhat.com>
* glib/gfileutils.c (get_contents_regfile): Fix double
close of file descriptor on error. (#82139, Wayne Schuller)
* glib/gspawn.c (close_and_invalidate): Don't close
fd's that have already been closed. (Fix from Michael
Meeks, #81959)
* glib/giochannel.c (g_io_channel_close): If not flushing,
dump the contents of the write buffers, so we won't try
to write them to an invalid fd later. (Patch from Ron Steinke,
fixing #78290, Andreas Persenius.)
2002-05-18 Matthias Clasen <maclas@gmx.de>
* tests/markups/fail-36.gmarkup:

View File

@ -1,3 +1,17 @@
Mon May 20 15:35:59 2002 Owen Taylor <otaylor@redhat.com>
* glib/gfileutils.c (get_contents_regfile): Fix double
close of file descriptor on error. (#82139, Wayne Schuller)
* glib/gspawn.c (close_and_invalidate): Don't close
fd's that have already been closed. (Fix from Michael
Meeks, #81959)
* glib/giochannel.c (g_io_channel_close): If not flushing,
dump the contents of the write buffers, so we won't try
to write them to an invalid fd later. (Patch from Ron Steinke,
fixing #78290, Andreas Persenius.)
2002-05-18 Matthias Clasen <maclas@gmx.de>
* tests/markups/fail-36.gmarkup:

View File

@ -1,3 +1,17 @@
Mon May 20 15:35:59 2002 Owen Taylor <otaylor@redhat.com>
* glib/gfileutils.c (get_contents_regfile): Fix double
close of file descriptor on error. (#82139, Wayne Schuller)
* glib/gspawn.c (close_and_invalidate): Don't close
fd's that have already been closed. (Fix from Michael
Meeks, #81959)
* glib/giochannel.c (g_io_channel_close): If not flushing,
dump the contents of the write buffers, so we won't try
to write them to an invalid fd later. (Patch from Ron Steinke,
fixing #78290, Andreas Persenius.)
2002-05-18 Matthias Clasen <maclas@gmx.de>
* tests/markups/fail-36.gmarkup:

View File

@ -1,3 +1,17 @@
Mon May 20 15:35:59 2002 Owen Taylor <otaylor@redhat.com>
* glib/gfileutils.c (get_contents_regfile): Fix double
close of file descriptor on error. (#82139, Wayne Schuller)
* glib/gspawn.c (close_and_invalidate): Don't close
fd's that have already been closed. (Fix from Michael
Meeks, #81959)
* glib/giochannel.c (g_io_channel_close): If not flushing,
dump the contents of the write buffers, so we won't try
to write them to an invalid fd later. (Patch from Ron Steinke,
fixing #78290, Andreas Persenius.)
2002-05-18 Matthias Clasen <maclas@gmx.de>
* tests/markups/fail-36.gmarkup:

View File

@ -1,3 +1,17 @@
Mon May 20 15:35:59 2002 Owen Taylor <otaylor@redhat.com>
* glib/gfileutils.c (get_contents_regfile): Fix double
close of file descriptor on error. (#82139, Wayne Schuller)
* glib/gspawn.c (close_and_invalidate): Don't close
fd's that have already been closed. (Fix from Michael
Meeks, #81959)
* glib/giochannel.c (g_io_channel_close): If not flushing,
dump the contents of the write buffers, so we won't try
to write them to an invalid fd later. (Patch from Ron Steinke,
fixing #78290, Andreas Persenius.)
2002-05-18 Matthias Clasen <maclas@gmx.de>
* tests/markups/fail-36.gmarkup:

View File

@ -1,3 +1,17 @@
Mon May 20 15:35:59 2002 Owen Taylor <otaylor@redhat.com>
* glib/gfileutils.c (get_contents_regfile): Fix double
close of file descriptor on error. (#82139, Wayne Schuller)
* glib/gspawn.c (close_and_invalidate): Don't close
fd's that have already been closed. (Fix from Michael
Meeks, #81959)
* glib/giochannel.c (g_io_channel_close): If not flushing,
dump the contents of the write buffers, so we won't try
to write them to an invalid fd later. (Patch from Ron Steinke,
fixing #78290, Andreas Persenius.)
2002-05-18 Matthias Clasen <maclas@gmx.de>
* tests/markups/fail-36.gmarkup:

View File

@ -416,8 +416,6 @@ get_contents_regfile (const gchar *filename,
{
if (errno != EINTR)
{
close (fd);
g_free (buf);
g_set_error (error,

View File

@ -346,27 +346,35 @@ g_io_channel_shutdown (GIOChannel *channel,
g_return_val_if_fail (channel != NULL, G_IO_STATUS_ERROR);
g_return_val_if_fail (err == NULL || *err == NULL, G_IO_STATUS_ERROR);
if (flush && channel->write_buf && channel->write_buf->len > 0)
if (channel->write_buf && channel->write_buf->len > 0)
{
GIOFlags flags;
/* Set the channel to blocking, to avoid a busy loop
*/
flags = g_io_channel_get_flags (channel);
/* Ignore any errors here, they're irrelevant */
g_io_channel_set_flags (channel, flags & ~G_IO_FLAG_NONBLOCK, NULL);
result = g_io_channel_flush (channel, &tmperr);
if (channel->partial_write_buf[0] != '\0')
if (flush)
{
g_warning ("Partial character at end of write buffer not flushed.\n");
channel->partial_write_buf[0] = '\0';
GIOFlags flags;
/* Set the channel to blocking, to avoid a busy loop
*/
flags = g_io_channel_get_flags (channel);
/* Ignore any errors here, they're irrelevant */
g_io_channel_set_flags (channel, flags & ~G_IO_FLAG_NONBLOCK, NULL);
result = g_io_channel_flush (channel, &tmperr);
}
else
result = G_IO_STATUS_NORMAL;
g_string_truncate(channel->write_buf, 0);
}
else
result = G_IO_STATUS_NORMAL;
if (channel->partial_write_buf[0] != '\0')
{
if (flush)
g_warning ("Partial character at end of write buffer not flushed.\n");
channel->partial_write_buf[0] = '\0';
}
status = channel->funcs->io_close (channel, err);
channel->close_on_unref = FALSE; /* Because we already did */

View File

@ -119,8 +119,13 @@ close_and_invalidate (gint *fd)
{
gint ret;
ret = close (*fd);
*fd = -1;
if (*fd < 0)
return -1;
else
{
ret = close (*fd);
*fd = -1;
}
return ret;
}