GApplication: Plug a memory leak
[platform/upstream/glib.git] / gio / win32 / gwinhttpfileinputstream.c
index 3a90374..909300e 100644 (file)
@@ -14,9 +14,7 @@
  * Lesser General Public License for more details.
  *
  * You should have received a copy of the GNU Lesser General
- * Public License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
- * Boston, MA 02111-1307, USA.
+ * Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
  *
  * Author: Alexander Larsson <alexl@redhat.com>
  * Author: Tor Lillqvist <tml@novell.com>
 
 #include <glib.h>
 
-#include "gcancellable.h"
-#include "gioerror.h"
+#include "gio/gcancellable.h"
+#include "gio/gioerror.h"
 #include "gwinhttpfileinputstream.h"
 #include "glibintl.h"
 
-#include "gioalias.h"
-
 struct _GWinHttpFileInputStream
 {
   GFileInputStream parent_instance;
@@ -57,6 +53,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 +69,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 +84,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
@@ -95,7 +99,7 @@ g_winhttp_file_input_stream_init (GWinHttpFileInputStream *info)
  * @request: handle to the HTTP request, as from WinHttpOpenRequest
  *
  * Returns: #GFileInputStream for the given request
- **/
+ */
 GFileInputStream *
 _g_winhttp_file_input_stream_new (GWinHttpFile *file,
                                   HINTERNET     connection,
@@ -105,7 +109,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 +160,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;
+}