utils: Use auto-pointers

This commit is contained in:
Marco Trevisan (Treviño)
2020-01-31 12:57:57 +01:00
committed by Benjamin Berg
parent 827baff301
commit 38ba7199b7
4 changed files with 25 additions and 36 deletions

View File

@ -28,7 +28,7 @@ static GDBusConnection *connection = NULL;
static void create_manager(void)
{
GError *error = NULL;
g_autoptr(GError) error = NULL;
connection = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, &error);
if (connection == NULL) {
@ -49,7 +49,7 @@ static void create_manager(void)
static void delete_fingerprints (FprintDBusDevice *dev, const char *username)
{
GError *error = NULL;
g_autoptr(GError) error = NULL;
if (!fprint_dbus_device_call_claim_sync (dev, username, NULL, &error)) {
g_print("failed to claim device: %s\n", error->message);
@ -76,12 +76,12 @@ static void delete_fingerprints (FprintDBusDevice *dev, const char *username)
} else {
g_print ("No fingerprints to delete on %s\n",
fprint_dbus_device_get_name (dev));
g_clear_error (&error);
}
} else {
g_print ("Fingerprints deleted on %s\n",
fprint_dbus_device_get_name (dev));
}
g_clear_error (&error);
if (!fprint_dbus_device_call_release_sync (dev, NULL, &error)) {
g_print("ReleaseDevice failed: %s\n", error->message);
@ -91,7 +91,7 @@ static void delete_fingerprints (FprintDBusDevice *dev, const char *username)
static void process_devices(char **argv)
{
GError *error = NULL;
g_autoptr(GError) error = NULL;
g_auto(GStrv) devices = NULL;
char *path;
guint num_devices;
@ -122,10 +122,11 @@ static void process_devices(char **argv)
path = devices[i];
g_print("Using device %s\n", path);
/* NOTE: We should handle error cases! */
dev = fprint_dbus_device_proxy_new_sync (connection,
G_DBUS_PROXY_FLAGS_NONE,
"net.reactivated.Fprint",
path, NULL, &error);
path, NULL, NULL);
for (j = 1; argv[j] != NULL; j++)
delete_fingerprints (dev, argv[j]);

View File

@ -35,7 +35,7 @@ static char **usernames = NULL;
static void create_manager(void)
{
GError *error = NULL;
g_autoptr(GError) error = NULL;
connection = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, &error);
if (connection == NULL) {
@ -57,8 +57,8 @@ static void create_manager(void)
static FprintDBusDevice *open_device (const char *username)
{
g_autoptr(FprintDBusDevice) dev = NULL;
GError *error = NULL;
gchar *path;
g_autoptr(GError) error = NULL;
g_autofree char *path = NULL;
if (!fprint_dbus_manager_call_get_default_device_sync (manager, &path,
NULL, &error)) {
@ -73,8 +73,6 @@ static FprintDBusDevice *open_device (const char *username)
"net.reactivated.Fprint",
path, NULL, &error);
g_free (path);
if (error) {
g_print ("failed to connect to device: %s\n", error->message);
exit (1);
@ -112,7 +110,7 @@ static void proxy_signal_cb (GDBusProxy *proxy,
static void do_enroll (FprintDBusDevice *dev)
{
GError *error = NULL;
g_autoptr(GError) error = NULL;
gboolean enroll_completed = FALSE;
gboolean found;
guint i;
@ -128,7 +126,7 @@ static void do_enroll (FprintDBusDevice *dev)
}
}
if (!found) {
GString *s;
g_autoptr(GString) s = NULL;
s = g_string_new (NULL);
g_string_append_printf (s, "Invalid finger name '%s'. Name must be one of ", finger_name);
@ -138,7 +136,6 @@ static void do_enroll (FprintDBusDevice *dev)
g_string_append (s, ", ");
}
g_warning ("%s", s->str);
g_string_free (s, TRUE);
exit (1);
}
@ -162,7 +159,7 @@ static void do_enroll (FprintDBusDevice *dev)
static void release_device (FprintDBusDevice *dev)
{
GError *error = NULL;
g_autoptr(GError) error = NULL;
if (!fprint_dbus_device_call_release_sync (dev, NULL, &error)) {
g_print("ReleaseDevice failed: %s\n", error->message);
exit (1);

View File

@ -28,7 +28,7 @@ static GDBusConnection *connection = NULL;
static void create_manager(void)
{
GError *error = NULL;
g_autoptr(GError) error = NULL;
connection = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, &error);
if (connection == NULL) {
@ -49,8 +49,8 @@ static void create_manager(void)
static void list_fingerprints (FprintDBusDevice *dev, const char *username)
{
GError *error = NULL;
char **fingers;
g_autoptr(GError) error = NULL;
g_auto(GStrv) fingers = NULL;
guint i;
if (!fprint_dbus_device_call_list_enrolled_fingers_sync (dev, username,
@ -69,9 +69,6 @@ static void list_fingerprints (FprintDBusDevice *dev, const char *username)
if (!ignore_error) {
g_print("ListEnrolledFingers failed: %s\n", error->message);
exit (1);
} else {
g_clear_error (&error);
fingers = NULL;
}
}
@ -89,14 +86,12 @@ static void list_fingerprints (FprintDBusDevice *dev, const char *username)
for (i = 0; fingers[i] != NULL; i++) {
g_print(" - #%d: %s\n", i, fingers[i]);
}
g_strfreev (fingers);
}
static void process_devices(char **argv)
{
g_auto(GStrv) devices = NULL;
GError *error = NULL;
g_autoptr(GError) error = NULL;
char *path;
guint num_devices;
guint i;
@ -126,10 +121,11 @@ static void process_devices(char **argv)
path = devices[i];
g_print("Using device %s\n", path);
/* NOTE: We should handle error cases! */
dev = fprint_dbus_device_proxy_new_sync (connection,
G_DBUS_PROXY_FLAGS_NONE,
"net.reactivated.Fprint",
path, NULL, &error);
path, NULL, NULL);
for (j = 1; argv[j] != NULL; j++)
list_fingerprints (dev, argv[j]);

View File

@ -55,8 +55,8 @@ static void create_manager(void)
static FprintDBusDevice *open_device (const char *username)
{
g_autoptr(FprintDBusDevice) dev = NULL;
GError *error = NULL;
gchar *path;
g_autoptr(GError) error = NULL;
g_autofree char *path = NULL;
if (!fprint_dbus_manager_call_get_default_device_sync (manager, &path,
NULL, &error)) {
@ -71,8 +71,6 @@ static FprintDBusDevice *open_device (const char *username)
"net.reactivated.Fprint",
path, NULL, &error);
g_free (path);
if (error) {
g_print ("failed to connect to device: %s\n", error->message);
exit (1);
@ -88,8 +86,8 @@ static FprintDBusDevice *open_device (const char *username)
static void find_finger (FprintDBusDevice *dev, const char *username)
{
GError *error = NULL;
char **fingers;
g_autoptr(GError) error = NULL;
g_auto(GStrv) fingers = NULL;
guint i;
if (!fprint_dbus_device_call_list_enrolled_fingers_sync (dev, username,
@ -120,8 +118,6 @@ static void find_finger (FprintDBusDevice *dev, const char *username)
if (finger_name == NULL) {
finger_name = g_strdup (fingers[0]);
}
g_strfreev (fingers);
}
static void verify_result(GObject *object, const char *result, gboolean done, void *user_data)
@ -159,7 +155,7 @@ static void proxy_signal_cb (GDBusProxy *proxy,
static void do_verify (FprintDBusDevice *dev)
{
GError *error = NULL;
g_autoptr(GError) error = NULL;
gboolean verify_completed = FALSE;
g_signal_connect (dev, "g-signal", G_CALLBACK (proxy_signal_cb),
@ -186,7 +182,7 @@ static void do_verify (FprintDBusDevice *dev)
static void release_device (FprintDBusDevice *dev)
{
GError *error = NULL;
g_autoptr(GError) error = NULL;
if (!fprint_dbus_device_call_release_sync (dev, NULL, &error)) {
g_print("ReleaseDevice failed: %s\n", error->message);
exit (1);
@ -203,8 +199,8 @@ static const GOptionEntry entries[] = {
int main(int argc, char **argv)
{
g_autoptr(FprintDBusDevice) dev = NULL;
g_autoptr(GError) err = NULL;
GOptionContext *context;
GError *err = NULL;
const char *username = NULL;
setlocale (LC_ALL, "");
@ -214,7 +210,6 @@ int main(int argc, char **argv)
if (g_option_context_parse (context, &argc, &argv, &err) == FALSE) {
g_print ("couldn't parse command-line options: %s\n", err->message);
g_error_free (err);
return 1;
}