Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 24 additions & 5 deletions src/udiskslinuxprovider.c
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,22 @@ uevent_is_spurious (GUdevDevice *dev)
return FALSE;
}

static void
probe_device_thread_func (GTask *task, gpointer source_object, gpointer task_data, GCancellable *cancellable)
{
ProbeRequest *request = task_data;
request->udisks_device = udisks_linux_device_new_sync (request->udev_device, udisks_linux_provider_get_udev_client(request->provider));
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing space before the opening parenthesis.

g_task_return_pointer (task, request, NULL);
}

static void
on_probe_job_completed (GObject *source_object, GAsyncResult *res, gpointer user_data)
{
GTask *task = G_TASK (res);
ProbeRequest *request = g_task_propagate_pointer (task, NULL);
g_idle_add (on_idle_with_probed_uevent, request);
}

static gpointer
probe_request_thread_func (gpointer user_data)
{
Expand Down Expand Up @@ -324,13 +340,16 @@ probe_request_thread_func (gpointer user_data)

/* ignore spurious uevents */
if (!request->known_block && uevent_is_spurious (request->udev_device))
continue;

/* probe the device - this may take a while */
request->udisks_device = udisks_linux_device_new_sync (request->udev_device, provider->gudev_client);
{
probe_request_free (request);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch!

I make separate PR with this fix leak.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Included in #1472 keeping your credits

continue;
}

/* now that we've probed the device, post the request back to the main thread */
g_idle_add (on_idle_with_probed_uevent, request);
GTask *task = g_task_new (provider, NULL, on_probe_job_completed, NULL);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please move the variable declaration to the top of the function along to others.

g_task_set_task_data (task, request, (GDestroyNotify) probe_request_free);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probe_request_free() is called within on_idle_with_probed_uevent(), this will actually result in double-free. I believe the destroy func is only called when replacing existing data, i.e. when this function is called twice and more, which is not the case here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probe_request_free() is called within on_idle_with_probed_uevent(), this will actually result in double-free. I believe the destroy func is only called when replacing existing data, i.e. when this function is called twice and more, which is not the case here.

Do you have any assumptions on how to get around double free, maybe do the check inside function?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just pass NULL here as the thread func will always succeed.

g_task_run_in_thread (task, probe_device_thread_func);
g_object_unref (task);
}
while (TRUE);

Expand Down
Loading