summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Zeuthen <davidz@redhat.com>2012-01-27 13:00:00 -0500
committerDavid Zeuthen <davidz@redhat.com>2012-01-27 13:00:00 -0500
commit8e9b82e8211da586bb78466e0f9c0e306028b1d1 (patch)
tree3db200a5b5daacac6ce1851718936b30657f51d7
parent04fc29e4213c595dfbcfad153425e91e9dbf97b7 (diff)
Fix a couple of uninitialized warnings and simplify SMART self-test handling
In particular, this fixes a crash when running a SMART self-test on a drive and then yanking it. Signed-off-by: David Zeuthen <davidz@redhat.com>
-rw-r--r--src/udiskslinuxblock.c11
-rw-r--r--src/udiskslinuxdrive.c5
-rw-r--r--src/udiskslinuxdriveata.c31
3 files changed, 20 insertions, 27 deletions
diff --git a/src/udiskslinuxblock.c b/src/udiskslinuxblock.c
index ba69f60..abc50dd 100644
--- a/src/udiskslinuxblock.c
+++ b/src/udiskslinuxblock.c
@@ -414,13 +414,12 @@ find_crypttab_entries_for_device (UDisksLinuxBlock *block,
UDisksCrypttabEntry *entry = UDISKS_CRYPTTAB_ENTRY (l->data);
const gchar *const *symlinks;
const gchar *device_in_entry;
- const gchar *device;
- const gchar *label;
- const gchar *uuid;
+ const gchar *device = NULL;
+ const gchar *label = NULL;
+ const gchar *uuid = NULL;
guint n;
device_in_entry = udisks_crypttab_entry_get_device (entry);
- device = NULL;
if (g_str_has_prefix (device_in_entry, "UUID="))
{
uuid = device_in_entry + 5;
@@ -1812,8 +1811,8 @@ handle_format (UDisksBlock *block,
const gchar *action_id;
const FSInfo *fs_info;
const gchar *label;
- gchar *escaped_label;
- gchar *command;
+ gchar *escaped_label = NULL;
+ gchar *command = NULL;
gchar *tmp;
gchar *error_message;
GError *error;
diff --git a/src/udiskslinuxdrive.c b/src/udiskslinuxdrive.c
index 326bc30..da293ae 100644
--- a/src/udiskslinuxdrive.c
+++ b/src/udiskslinuxdrive.c
@@ -675,7 +675,7 @@ handle_eject (UDisksDrive *_drive,
{
UDisksLinuxDrive *drive = UDISKS_LINUX_DRIVE (_drive);
UDisksLinuxDriveObject *object;
- UDisksLinuxBlockObject *block_object;
+ UDisksLinuxBlockObject *block_object = NULL;
UDisksBlock *block;
UDisksDaemon *daemon;
const gchar *action_id;
@@ -743,8 +743,7 @@ handle_eject (UDisksDrive *_drive,
udisks_drive_complete_eject (UDISKS_DRIVE (drive), invocation);
out:
- if (block_object != NULL)
- g_object_unref (block_object);
+ g_clear_object (&block_object);
g_free (error_message);
g_clear_object (&object);
return TRUE; /* returning TRUE means that we handled the method invocation */
diff --git a/src/udiskslinuxdriveata.c b/src/udiskslinuxdriveata.c
index 5145f74..cc3659c 100644
--- a/src/udiskslinuxdriveata.c
+++ b/src/udiskslinuxdriveata.c
@@ -42,6 +42,7 @@
#include "udisksdaemon.h"
#include "udiskscleanup.h"
#include "udisksdaemonutil.h"
+#include "udisksbasejob.h"
#include "udisksthreadedjob.h"
/**
@@ -79,7 +80,6 @@ struct _UDisksLinuxDriveAta
GVariant *smart_attributes;
UDisksThreadedJob *selftest_job;
- GCancellable *selftest_cancellable;
};
struct _UDisksLinuxDriveAtaClass
@@ -337,8 +337,8 @@ udisks_linux_drive_ata_refresh_smart_sync (UDisksLinuxDriveAta *drive,
GError **error)
{
UDisksLinuxDriveObject *object;
- GUdevDevice *device;
- gboolean ret;
+ GUdevDevice *device = NULL;
+ gboolean ret = FALSE;
SkDisk *d = NULL;
SkBool awake;
SkBool good;
@@ -357,9 +357,6 @@ udisks_linux_drive_ata_refresh_smart_sync (UDisksLinuxDriveAta *drive,
/* TODO: use cancellable */
- d = NULL;
- ret = FALSE;
-
if (simulate_path != NULL)
{
gchar *blob;
@@ -481,7 +478,7 @@ udisks_linux_drive_ata_refresh_smart_sync (UDisksLinuxDriveAta *drive,
ret = TRUE;
out:
- g_object_unref (device);
+ g_clear_object (&device);
if (d != NULL)
sk_disk_free (d);
g_clear_object (&object);
@@ -563,7 +560,7 @@ udisks_linux_drive_ata_smart_selftest_sync (UDisksLinuxDriveAta *drive,
ret = TRUE;
out:
- g_object_unref (device);
+ g_clear_object (&device);
if (d != NULL)
sk_disk_free (d);
g_clear_object (&object);
@@ -579,7 +576,7 @@ handle_smart_update (UDisksDriveAta *_drive,
{
UDisksLinuxDriveAta *drive = UDISKS_LINUX_DRIVE_ATA (_drive);
UDisksLinuxDriveObject *object;
- UDisksLinuxBlockObject *block_object;
+ UDisksLinuxBlockObject *block_object = NULL;
UDisksDaemon *daemon;
gboolean nowakeup = FALSE;
const gchar *atasmart_blob = NULL;
@@ -675,8 +672,7 @@ handle_smart_update (UDisksDriveAta *_drive,
udisks_drive_ata_complete_smart_update (UDISKS_DRIVE_ATA (drive), invocation);
out:
- if (block_object != NULL)
- g_object_unref (block_object);
+ g_clear_object (&block_object);
g_clear_object (&object);
return TRUE; /* returning TRUE means that we handled the method invocation */
}
@@ -771,13 +767,14 @@ handle_smart_selftest_abort (UDisksDriveAta *_drive,
goto out;
}
- /* TODO: wakeup selftest thread and wait for it to terminate */
+ /* This wakes up the selftest thread */
G_LOCK (object_lock);
- if (drive->selftest_cancellable != NULL)
+ if (drive->selftest_job != NULL)
{
- g_cancellable_cancel (drive->selftest_cancellable);
+ g_cancellable_cancel (udisks_base_job_get_cancellable (UDISKS_BASE_JOB (drive->selftest_job)));
}
G_UNLOCK (object_lock);
+ /* TODO: wait for the selftest thread to terminate */
error = NULL;
if (!udisks_linux_drive_ata_refresh_smart_sync (drive,
@@ -878,10 +875,9 @@ selftest_job_func (UDisksThreadedJob *job,
ret = TRUE;
out:
+ /* terminate the job */
G_LOCK (object_lock);
drive->selftest_job = NULL;
- if (drive->selftest_cancellable != NULL)
- g_object_unref (drive->selftest_cancellable);
G_UNLOCK (object_lock);
g_clear_object (&object);
return ret;
@@ -965,13 +961,12 @@ handle_smart_selftest_start (UDisksDriveAta *_drive,
G_LOCK (object_lock);
if (drive->selftest_job == NULL)
{
- drive->selftest_cancellable = g_cancellable_new ();
drive->selftest_job = UDISKS_THREADED_JOB (udisks_daemon_launch_threaded_job (daemon,
UDISKS_OBJECT (object),
selftest_job_func,
g_object_ref (drive),
g_object_unref,
- drive->selftest_cancellable));
+ NULL)); /* GCancellable */
}
G_UNLOCK (object_lock);