[tracker/extractor-dbus-fd] FS miner: group alloc and free for FD passing
- From: Adrien Bustany <abustany src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/extractor-dbus-fd] FS miner: group alloc and free for FD passing
- Date: Fri, 2 Jul 2010 13:03:24 +0000 (UTC)
commit 15f54c8a51e729c462859f621e136ef8c1269554
Author: Adrien Bustany <abustany gnome org>
Date: Fri Jul 2 10:18:40 2010 +0200
FS miner: group alloc and free for FD passing
This commit adds two functions, fast_async_data_(new,free) to centralize
allocs and unrefs for the FastAsyncData structure. Hopefully it'll make
memory leaks easier to spot.
src/miners/fs/tracker-miner-files.c | 60 ++++++++++++++++++++++++----------
1 files changed, 42 insertions(+), 18 deletions(-)
---
diff --git a/src/miners/fs/tracker-miner-files.c b/src/miners/fs/tracker-miner-files.c
index 815aa21..f6ffa61 100644
--- a/src/miners/fs/tracker-miner-files.c
+++ b/src/miners/fs/tracker-miner-files.c
@@ -80,11 +80,11 @@ struct ProcessFileData {
};
typedef struct {
- ProcessFileData *process_file_data;
GInputStream *buffered_input_stream;
GInputStream *unix_input_stream;
GOutputStream *output_stream;
org_freedesktop_Tracker1_Extract_get_metadata_reply callback;
+ gpointer user_data;
} FastAsyncData;
struct TrackerMinerFilesPrivate {
@@ -1940,12 +1940,42 @@ extractor_get_embedded_metadata_cancel (GCancellable *cancellable,
}
#ifdef HAVE_DBUS_FD_PASSING
+static FastAsyncData*
+fast_async_data_new (GInputStream *unix_input_stream,
+ GInputStream *buffered_input_stream,
+ GOutputStream *output_stream,
+ org_freedesktop_Tracker1_Extract_get_metadata_reply callback,
+ gpointer user_data)
+{
+ FastAsyncData *data;
+
+ data = g_slice_new0 (FastAsyncData);
+ data->unix_input_stream = unix_input_stream;
+ data->buffered_input_stream = buffered_input_stream;
+ data->output_stream = output_stream;
+ data->callback = callback;
+ data->user_data = user_data;
+
+ return data;
+}
+
+static void
+fast_async_data_free (FastAsyncData *data)
+{
+ g_object_unref (data->unix_input_stream);
+ g_object_unref (data->buffered_input_stream);
+ g_object_unref (data->output_stream);
+
+ g_slice_free (FastAsyncData, data);
+}
+
static void
get_metadata_fast_cb (GObject *source_object,
GAsyncResult *result,
gpointer user_data)
{
FastAsyncData *data;
+ ProcessFileData *process_data;
DBusMessage *reply;
GError *error = NULL;
gsize buffer_size;
@@ -1953,22 +1983,17 @@ get_metadata_fast_cb (GObject *source_object,
gchar *sparql = NULL;
data = user_data;
+ process_data = data->user_data;
buffer_size = g_output_stream_splice_finish (data->output_stream,
result,
&error);
- g_object_unref (data->buffered_input_stream);
- g_object_unref (data->unix_input_stream);
-
preupdate = g_memory_output_stream_get_data (G_MEMORY_OUTPUT_STREAM (data->output_stream));
-
- g_object_unref (data->output_stream);
-
if (G_UNLIKELY (error)) {
if (error->code != G_IO_ERROR_CANCELLED) {
/* ProcessFileData and error are freed in the callback */
- (* data->callback) (NULL, NULL, NULL, error, data->process_file_data);
+ (* data->callback) (NULL, NULL, NULL, error, process_data);
} else {
/* ProcessFileData was freed in
* extractor_get_embedded_metadata_cancel
@@ -1976,7 +2001,7 @@ get_metadata_fast_cb (GObject *source_object,
g_error_free (error);
}
} else {
- DBusPendingCall *call = data->process_file_data->call;
+ DBusPendingCall *call = process_data->call;
dbus_pending_call_block (call);
reply = dbus_pending_call_steal_reply (call);
@@ -1989,7 +2014,7 @@ get_metadata_fast_cb (GObject *source_object,
dbus_set_g_error (&error, &dbus_error);
/* callback frees the error */
- (* data->callback) (NULL, NULL, NULL, error, data->process_file_data);
+ (* data->callback) (NULL, NULL, NULL, error, process_data);
dbus_error_free (&dbus_error);
} else {
@@ -1998,14 +2023,14 @@ get_metadata_fast_cb (GObject *source_object,
sparql = preupdate + strlen (preupdate) + 1;
}
- (* data->callback) (NULL, preupdate, sparql, NULL, data->process_file_data);
+ (* data->callback) (NULL, preupdate, sparql, NULL, data->user_data);
g_free (preupdate);
}
dbus_message_unref (reply);
}
- g_slice_free (FastAsyncData, data);
+ fast_async_data_free (data);
}
static DBusPendingCall*
@@ -2060,12 +2085,11 @@ get_metadata_fast_async (DBusConnection *connection,
64*1024);
output_stream = g_memory_output_stream_new (NULL, 0, g_realloc, NULL);
- data = g_slice_new0 (FastAsyncData);
- data->process_file_data = user_data;
- data->buffered_input_stream = buffered_input_stream;
- data->unix_input_stream = unix_input_stream;
- data->output_stream = output_stream;
- data->callback = callback;
+ data = fast_async_data_new (unix_input_stream,
+ buffered_input_stream,
+ output_stream,
+ callback,
+ user_data);
g_output_stream_splice_async (output_stream,
buffered_input_stream,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]