summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHans Breuer <hans@breuer.org>2009-05-27 15:12:31 +0300
committerTor Lillqvist <tml@iki.fi>2009-05-27 15:16:38 +0300
commit8607901a7406371d55874bb6c291351b4b0c4547 (patch)
tree82c84892e6913f8aa37f317032319f293f16717d
parentcd7e05bd0d00e3d9eb4f96c1fc15eb9db8252c9f (diff)
downloadglib-8607901a7406371d55874bb6c291351b4b0c4547.tar.gz
Correct reference and implement close_fn (#578769)
Do proper referencing and unreferencing of GWinHttpFileInputStream::file and GWinHttpFileInputStream::file::vfs. Implement GWinHttpFileInputStream::close_fn.
-rw-r--r--gio/win32/gwinhttpfile.c5
-rw-r--r--gio/win32/gwinhttpfileinputstream.c23
2 files changed, 26 insertions, 2 deletions
diff --git a/gio/win32/gwinhttpfile.c b/gio/win32/gwinhttpfile.c
index 6bd05b7f4..a4709ed4d 100644
--- a/gio/win32/gwinhttpfile.c
+++ b/gio/win32/gwinhttpfile.c
@@ -24,6 +24,7 @@
#include "config.h"
+#include <stdio.h>
#include <string.h>
#include <wchar.h>
@@ -60,6 +61,8 @@ g_winhttp_file_finalize (GObject *object)
g_free (file->url.lpszUrlPath);
g_free (file->url.lpszExtraInfo);
+ g_object_unref (file->vfs);
+
G_OBJECT_CLASS (g_winhttp_file_parent_class)->finalize (object);
}
@@ -96,7 +99,7 @@ _g_winhttp_file_new (GWinHttpVfs *vfs,
return NULL;
file = g_object_new (G_TYPE_WINHTTP_FILE, NULL);
- file->vfs = vfs;
+ file->vfs = g_object_ref (vfs);
memset (&file->url, 0, sizeof (file->url));
file->url.dwStructSize = sizeof (file->url);
diff --git a/gio/win32/gwinhttpfileinputstream.c b/gio/win32/gwinhttpfileinputstream.c
index 3a903742e..f18a93a96 100644
--- a/gio/win32/gwinhttpfileinputstream.c
+++ b/gio/win32/gwinhttpfileinputstream.c
@@ -57,6 +57,10 @@ static gssize g_winhttp_file_input_stream_read (GInputStream *stream,
GCancellable *cancellable,
GError **error);
+static gboolean g_winhttp_file_input_stream_close (GInputStream *stream,
+ GCancellable *cancellable,
+ GError **error);
+
static void
g_winhttp_file_input_stream_finalize (GObject *object)
{
@@ -69,6 +73,9 @@ g_winhttp_file_input_stream_finalize (GObject *object)
if (winhttp_stream->connection != NULL)
G_WINHTTP_VFS_GET_CLASS (winhttp_stream->file->vfs)->funcs->pWinHttpCloseHandle (winhttp_stream->connection);
+ g_object_unref (winhttp_stream->file);
+ winhttp_stream->file = NULL;
+
G_OBJECT_CLASS (g_winhttp_file_input_stream_parent_class)->finalize (object);
}
@@ -81,6 +88,7 @@ g_winhttp_file_input_stream_class_init (GWinHttpFileInputStreamClass *klass)
gobject_class->finalize = g_winhttp_file_input_stream_finalize;
stream_class->read_fn = g_winhttp_file_input_stream_read;
+ stream_class->close_fn = g_winhttp_file_input_stream_close;
}
static void
@@ -105,7 +113,7 @@ _g_winhttp_file_input_stream_new (GWinHttpFile *file,
stream = g_object_new (G_TYPE_WINHTTP_FILE_INPUT_STREAM, NULL);
- stream->file = file;
+ stream->file = g_object_ref (file);
stream->request_sent = FALSE;
stream->connection = connection;
stream->request = request;
@@ -156,3 +164,16 @@ g_winhttp_file_input_stream_read (GInputStream *stream,
return bytes_read;
}
+
+static gboolean
+g_winhttp_file_input_stream_close (GInputStream *stream,
+ GCancellable *cancellable,
+ GError **error)
+{
+ GWinHttpFileInputStream *winhttp_stream = G_WINHTTP_FILE_INPUT_STREAM (stream);
+
+ if (winhttp_stream->connection != NULL)
+ G_WINHTTP_VFS_GET_CLASS (winhttp_stream->file->vfs)->funcs->pWinHttpCloseHandle (winhttp_stream->connection);
+ winhttp_stream->connection = NULL;
+ return TRUE;
+}