From 81ad1bb215d718b16e7e68ac0d95e078e766234e Mon Sep 17 00:00:00 2001 From: Owen Taylor Date: Mon, 20 May 2002 19:36:58 +0000 Subject: [PATCH] Fix double close of file descriptor on error. (#82139, Wayne Schuller) Mon May 20 15:35:59 2002 Owen Taylor * 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.) --- ChangeLog | 14 ++++++++++++++ ChangeLog.pre-2-10 | 14 ++++++++++++++ ChangeLog.pre-2-12 | 14 ++++++++++++++ ChangeLog.pre-2-2 | 14 ++++++++++++++ ChangeLog.pre-2-4 | 14 ++++++++++++++ ChangeLog.pre-2-6 | 14 ++++++++++++++ ChangeLog.pre-2-8 | 14 ++++++++++++++ glib/gfileutils.c | 2 -- glib/giochannel.c | 34 +++++++++++++++++++++------------- glib/gspawn.c | 9 +++++++-- 10 files changed, 126 insertions(+), 17 deletions(-) diff --git a/ChangeLog b/ChangeLog index 311a2c7..9154a4e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,17 @@ +Mon May 20 15:35:59 2002 Owen Taylor + + * 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 * tests/markups/fail-36.gmarkup: diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index 311a2c7..9154a4e 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,3 +1,17 @@ +Mon May 20 15:35:59 2002 Owen Taylor + + * 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 * tests/markups/fail-36.gmarkup: diff --git a/ChangeLog.pre-2-12 b/ChangeLog.pre-2-12 index 311a2c7..9154a4e 100644 --- a/ChangeLog.pre-2-12 +++ b/ChangeLog.pre-2-12 @@ -1,3 +1,17 @@ +Mon May 20 15:35:59 2002 Owen Taylor + + * 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 * tests/markups/fail-36.gmarkup: diff --git a/ChangeLog.pre-2-2 b/ChangeLog.pre-2-2 index 311a2c7..9154a4e 100644 --- a/ChangeLog.pre-2-2 +++ b/ChangeLog.pre-2-2 @@ -1,3 +1,17 @@ +Mon May 20 15:35:59 2002 Owen Taylor + + * 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 * tests/markups/fail-36.gmarkup: diff --git a/ChangeLog.pre-2-4 b/ChangeLog.pre-2-4 index 311a2c7..9154a4e 100644 --- a/ChangeLog.pre-2-4 +++ b/ChangeLog.pre-2-4 @@ -1,3 +1,17 @@ +Mon May 20 15:35:59 2002 Owen Taylor + + * 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 * tests/markups/fail-36.gmarkup: diff --git a/ChangeLog.pre-2-6 b/ChangeLog.pre-2-6 index 311a2c7..9154a4e 100644 --- a/ChangeLog.pre-2-6 +++ b/ChangeLog.pre-2-6 @@ -1,3 +1,17 @@ +Mon May 20 15:35:59 2002 Owen Taylor + + * 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 * tests/markups/fail-36.gmarkup: diff --git a/ChangeLog.pre-2-8 b/ChangeLog.pre-2-8 index 311a2c7..9154a4e 100644 --- a/ChangeLog.pre-2-8 +++ b/ChangeLog.pre-2-8 @@ -1,3 +1,17 @@ +Mon May 20 15:35:59 2002 Owen Taylor + + * 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 * tests/markups/fail-36.gmarkup: diff --git a/glib/gfileutils.c b/glib/gfileutils.c index feeba79..4108e19 100644 --- a/glib/gfileutils.c +++ b/glib/gfileutils.c @@ -416,8 +416,6 @@ get_contents_regfile (const gchar *filename, { if (errno != EINTR) { - close (fd); - g_free (buf); g_set_error (error, diff --git a/glib/giochannel.c b/glib/giochannel.c index f50eee8..c5e8978 100644 --- a/glib/giochannel.c +++ b/glib/giochannel.c @@ -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; + if (flush) + { + 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); + /* 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); - if (channel->partial_write_buf[0] != '\0') - { - g_warning ("Partial character at end of write buffer not flushed.\n"); - channel->partial_write_buf[0] = '\0'; + 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 */ diff --git a/glib/gspawn.c b/glib/gspawn.c index 33960e0..bf152f4 100644 --- a/glib/gspawn.c +++ b/glib/gspawn.c @@ -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; } -- 2.7.4