Commit 86976e6c authored by Marco Trevisan's avatar Marco Trevisan
Browse files

utils: Use auto-pointers

parent 6289c0f0
......@@ -29,7 +29,7 @@ static DBusGConnection *connection = NULL;
static void create_manager(void)
{
GError *error = NULL;
g_autoptr(GError) error = NULL;
connection = dbus_g_bus_get(DBUS_BUS_SYSTEM, &error);
if (connection == NULL) {
......@@ -44,8 +44,8 @@ static void create_manager(void)
static void delete_fingerprints(DBusGProxy *dev, const char *username)
{
GError *error = NULL;
GHashTable *props;
g_autoptr(GError) error = NULL;
g_autoptr(GHashTable) props = NULL;
DBusGProxy *p;
p = dbus_g_proxy_new_from_proxy(dev, "org.freedesktop.DBus.Properties", NULL);
......@@ -77,14 +77,13 @@ static void delete_fingerprints(DBusGProxy *dev, const char *username)
exit (1);
}
g_hash_table_destroy (props);
g_object_unref (p);
}
static void process_devices(char **argv)
{
GError *error = NULL;
GPtrArray *devices;
g_autoptr(GError) error = NULL;
g_autoptr(GPtrArray) devices = NULL;
char *path;
guint i;
......@@ -93,6 +92,8 @@ static void process_devices(char **argv)
exit (1);
}
g_ptr_array_set_free_func (devices, g_free);
if (devices->len == 0) {
g_print("No devices found\n");
exit(1);
......@@ -120,9 +121,6 @@ static void process_devices(char **argv)
g_object_unref (dev);
}
g_ptr_array_foreach(devices, (GFunc) g_free, NULL);
g_ptr_array_free(devices, TRUE);
}
int main(int argc, char **argv)
......
......@@ -37,7 +37,7 @@ static char **usernames = NULL;
static void create_manager(void)
{
GError *error = NULL;
g_autoptr(GError) error = NULL;
connection = dbus_g_bus_get(DBUS_BUS_SYSTEM, &error);
if (connection == NULL) {
......@@ -52,9 +52,9 @@ static void create_manager(void)
static DBusGProxy *open_device(const char *username)
{
GError *error = NULL;
gchar *path;
DBusGProxy *dev;
g_autoptr(GError) error = NULL;
g_autofree char *path = NULL;
if (!net_reactivated_Fprint_Manager_get_default_device(manager, &path, &error)) {
g_print("list_devices failed: %s\n", error->message);
......@@ -72,7 +72,6 @@ static DBusGProxy *open_device(const char *username)
dev = dbus_g_proxy_new_for_name(connection, "net.reactivated.Fprint",
path, "net.reactivated.Fprint.Device");
g_free (path);
if (!net_reactivated_Fprint_Device_claim(dev, username, &error)) {
g_print("failed to claim device: %s\n", error->message);
......@@ -91,7 +90,7 @@ static void enroll_result(GObject *object, const char *result, gboolean done, vo
static void do_enroll(DBusGProxy *dev)
{
GError *error = NULL;
g_autoptr(GError) error = NULL;
gboolean enroll_completed = FALSE;
gboolean found;
guint i;
......@@ -108,7 +107,7 @@ static void do_enroll(DBusGProxy *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);
......@@ -118,7 +117,6 @@ static void do_enroll(DBusGProxy *dev)
g_string_append (s, ", ");
}
g_warning ("%s", s->str);
g_string_free (s, TRUE);
exit (1);
}
......@@ -142,7 +140,7 @@ static void do_enroll(DBusGProxy *dev)
static void release_device(DBusGProxy *dev)
{
GError *error = NULL;
g_autoptr(GError) error = NULL;
if (!net_reactivated_Fprint_Device_release(dev, &error)) {
g_print("ReleaseDevice failed: %s\n", error->message);
exit (1);
......
......@@ -29,7 +29,7 @@ static DBusGConnection *connection = NULL;
static void create_manager(void)
{
GError *error = NULL;
g_autoptr(GError) error = NULL;
connection = dbus_g_bus_get(DBUS_BUS_SYSTEM, &error);
if (connection == NULL) {
......@@ -44,9 +44,9 @@ static void create_manager(void)
static void list_fingerprints(DBusGProxy *dev, const char *username)
{
GError *error = NULL;
char **fingers;
GHashTable *props;
g_autoptr(GError) error = NULL;
g_auto(GStrv) fingers = NULL;
g_autoptr(GHashTable) props = NULL;
DBusGProxy *p;
guint i;
......@@ -76,20 +76,17 @@ static void list_fingerprints(DBusGProxy *dev, const char *username)
username,
g_value_get_string (g_hash_table_lookup (props, "name")),
g_value_get_string (g_hash_table_lookup (props, "scan-type")));
g_hash_table_destroy (props);
g_object_unref (p);
for (i = 0; fingers[i] != NULL; i++) {
g_print(" - #%d: %s\n", i, fingers[i]);
}
g_strfreev (fingers);
}
static void process_devices(char **argv)
{
GError *error = NULL;
GPtrArray *devices;
g_autoptr(GPtrArray) devices = NULL;
g_autoptr(GError) error = NULL;
char *path;
guint i;
......@@ -98,6 +95,8 @@ static void process_devices(char **argv)
exit (1);
}
g_ptr_array_set_free_func (devices, g_free);
if (devices->len == 0) {
g_print("No devices found\n");
exit(1);
......@@ -125,9 +124,6 @@ static void process_devices(char **argv)
g_object_unref (dev);
}
g_ptr_array_foreach(devices, (GFunc) g_free, NULL);
g_ptr_array_free(devices, TRUE);
}
int main(int argc, char **argv)
......
......@@ -49,8 +49,8 @@ static void create_manager(void)
static DBusGProxy *open_device(const char *username)
{
GError *error = NULL;
gchar *path;
g_autoptr(GError) error = NULL;
g_autofree char *path = NULL;
DBusGProxy *dev;
if (!net_reactivated_Fprint_Manager_get_default_device(manager, &path, &error)) {
......@@ -69,8 +69,6 @@ static DBusGProxy *open_device(const char *username)
dev = dbus_g_proxy_new_for_name(connection, "net.reactivated.Fprint",
path, "net.reactivated.Fprint.Device");
g_free (path);
if (!net_reactivated_Fprint_Device_claim(dev, username, &error)) {
g_print("failed to claim device: %s\n", error->message);
exit (1);
......@@ -81,8 +79,8 @@ static DBusGProxy *open_device(const char *username)
static void find_finger(DBusGProxy *dev, const char *username)
{
GError *error = NULL;
char **fingers;
g_autoptr(GError) error = NULL;
g_auto(GStrv) fingers = NULL;
guint i;
if (!net_reactivated_Fprint_Device_list_enrolled_fingers(dev, username, &fingers, &error)) {
......@@ -104,8 +102,6 @@ static void find_finger(DBusGProxy *dev, const char *username)
g_free (finger_name);
finger_name = g_strdup (fingers[0]);
}
g_strfreev (fingers);
}
static void verify_result(GObject *object, const char *result, gboolean done, void *user_data)
......@@ -123,7 +119,7 @@ static void verify_finger_selected(GObject *object, const char *name, void *user
static void do_verify(DBusGProxy *dev)
{
GError *error = NULL;
g_autoptr(GError) error = NULL;
gboolean verify_completed = FALSE;
dbus_g_proxy_add_signal(dev, "VerifyStatus", G_TYPE_STRING, G_TYPE_BOOLEAN, NULL);
......@@ -152,7 +148,7 @@ static void do_verify(DBusGProxy *dev)
static void release_device(DBusGProxy *dev)
{
GError *error = NULL;
g_autoptr(GError) error = NULL;
if (!net_reactivated_Fprint_Device_release(dev, &error)) {
g_print("ReleaseDevice failed: %s\n", error->message);
exit (1);
......@@ -169,7 +165,7 @@ static const GOptionEntry entries[] = {
int main(int argc, char **argv)
{
GOptionContext *context;
GError *err = NULL;
g_autoptr(GError) err = NULL;
DBusGProxy *dev;
const char *username = NULL;
......@@ -183,7 +179,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;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment