[glib] Check that close_fn is not %NULL before calling (#578499)
- From: Alexander Larsson <alexl src gnome org>
- To: svn-commits-list gnome org
- Subject: [glib] Check that close_fn is not %NULL before calling (#578499)
- Date: Wed, 20 May 2009 07:42:30 -0400 (EDT)
commit c20b8d4d53a4e90f0e822276f6fbd94d52ff3c85
Author: Alexander Larsson <alexl redhat com>
Date: Wed May 20 13:37:55 2009 +0200
Check that close_fn is not %NULL before calling (#578499)
Some streams have no close function, so this caused a crash.
---
gio/ginputstream.c | 13 ++++++++-----
gio/giostream.c | 11 +++++++----
gio/goutputstream.c | 18 +++++++++++-------
3 files changed, 26 insertions(+), 16 deletions(-)
diff --git a/gio/ginputstream.c b/gio/ginputstream.c
index 3d95c8b..d3e2224 100644
--- a/gio/ginputstream.c
+++ b/gio/ginputstream.c
@@ -1165,13 +1165,16 @@ close_async_thread (GSimpleAsyncResult *res,
cancellation, since we want to close things anyway, although
possibly in a quick-n-dirty way. At least we never want to leak
open handles */
-
+
class = G_INPUT_STREAM_GET_CLASS (object);
- result = class->close_fn (G_INPUT_STREAM (object), cancellable, &error);
- if (!result)
+ if (class->close_fn)
{
- g_simple_async_result_set_from_error (res, error);
- g_error_free (error);
+ result = class->close_fn (G_INPUT_STREAM (object), cancellable, &error);
+ if (!result)
+ {
+ g_simple_async_result_set_from_error (res, error);
+ g_error_free (error);
+ }
}
}
diff --git a/gio/giostream.c b/gio/giostream.c
index 7669734..a79e099 100644
--- a/gio/giostream.c
+++ b/gio/giostream.c
@@ -569,11 +569,14 @@ close_async_thread (GSimpleAsyncResult *res,
open handles */
class = G_IO_STREAM_GET_CLASS (object);
- result = class->close_fn (G_IO_STREAM (object), cancellable, &error);
- if (!result)
+ if (class->close_fn)
{
- g_simple_async_result_set_from_error (res, error);
- g_error_free (error);
+ result = class->close_fn (G_IO_STREAM (object), cancellable, &error);
+ if (!result)
+ {
+ g_simple_async_result_set_from_error (res, error);
+ g_error_free (error);
+ }
}
}
diff --git a/gio/goutputstream.c b/gio/goutputstream.c
index a040a51..9e2a875 100644
--- a/gio/goutputstream.c
+++ b/gio/goutputstream.c
@@ -456,13 +456,14 @@ g_output_stream_real_splice (GOutputStream *stream,
if (flags & G_OUTPUT_STREAM_SPLICE_CLOSE_TARGET)
{
/* But write errors on close are bad! */
- if (!class->close_fn (stream, cancellable, error))
+ if (class->close_fn &&
+ !class->close_fn (stream, cancellable, error))
res = FALSE;
}
if (res)
return bytes_copied;
-
+
return -1;
}
@@ -1307,13 +1308,16 @@ close_async_thread (GSimpleAsyncResult *res,
cancellation, since we want to close things anyway, although
possibly in a quick-n-dirty way. At least we never want to leak
open handles */
-
+
class = G_OUTPUT_STREAM_GET_CLASS (object);
- result = class->close_fn (G_OUTPUT_STREAM (object), cancellable, &error);
- if (!result)
+ if (class->close_fn)
{
- g_simple_async_result_set_from_error (res, error);
- g_error_free (error);
+ result = class->close_fn (G_OUTPUT_STREAM (object), cancellable, &error);
+ if (!result)
+ {
+ g_simple_async_result_set_from_error (res, error);
+ g_error_free (error);
+ }
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]