mirror of
https://gitlab.com/mishakmak/pam-fprint-grosshack.git
synced 2026-04-09 04:13:33 +02:00
device: Always use auto-pointers
Remove manual memory management when possible, using new GLib facilities In a few cases, avoid creating a temporary GError instead.
This commit is contained in:
committed by
Benjamin Berg
parent
e1c2698807
commit
1ae0f4926d
55
src/device.c
55
src/device.c
@ -489,9 +489,9 @@ _fprint_device_check_polkit_for_action (FprintDevice *rdev,
|
|||||||
{
|
{
|
||||||
FprintDevicePrivate *priv = fprint_device_get_instance_private(rdev);
|
FprintDevicePrivate *priv = fprint_device_get_instance_private(rdev);
|
||||||
const char *sender;
|
const char *sender;
|
||||||
PolkitSubject *subject;
|
g_autoptr(GError) _error = NULL;
|
||||||
PolkitAuthorizationResult *result;
|
g_autoptr(PolkitAuthorizationResult) result = NULL;
|
||||||
GError *_error = NULL;
|
g_autoptr(PolkitSubject) subject = NULL;
|
||||||
|
|
||||||
/* Check that caller is privileged */
|
/* Check that caller is privileged */
|
||||||
sender = g_dbus_method_invocation_get_sender (invocation);
|
sender = g_dbus_method_invocation_get_sender (invocation);
|
||||||
@ -503,13 +503,10 @@ _fprint_device_check_polkit_for_action (FprintDevice *rdev,
|
|||||||
NULL,
|
NULL,
|
||||||
POLKIT_CHECK_AUTHORIZATION_FLAGS_ALLOW_USER_INTERACTION,
|
POLKIT_CHECK_AUTHORIZATION_FLAGS_ALLOW_USER_INTERACTION,
|
||||||
NULL, &_error);
|
NULL, &_error);
|
||||||
g_object_unref (subject);
|
|
||||||
|
|
||||||
if (result == NULL) {
|
if (result == NULL) {
|
||||||
g_set_error (error, FPRINT_ERROR,
|
g_set_error (error, FPRINT_ERROR,
|
||||||
FPRINT_ERROR_PERMISSION_DENIED,
|
FPRINT_ERROR_PERMISSION_DENIED,
|
||||||
"Not Authorized: %s", _error->message);
|
"Not Authorized: %s", _error->message);
|
||||||
g_error_free (_error);
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -517,12 +514,9 @@ _fprint_device_check_polkit_for_action (FprintDevice *rdev,
|
|||||||
g_set_error (error, FPRINT_ERROR,
|
g_set_error (error, FPRINT_ERROR,
|
||||||
FPRINT_ERROR_PERMISSION_DENIED,
|
FPRINT_ERROR_PERMISSION_DENIED,
|
||||||
"Not Authorized: %s", action);
|
"Not Authorized: %s", action);
|
||||||
g_object_unref (result);
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
g_object_unref (result);
|
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1028,7 +1022,7 @@ static gboolean fprint_device_verify_start (FprintDBusDevice *dbus_dev,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (finger_num == -1) {
|
if (finger_num == -1) {
|
||||||
GSList *prints;
|
g_autoptr(GSList) prints = NULL;
|
||||||
|
|
||||||
prints = store.discover_prints(priv->dev, session->username);
|
prints = store.discover_prints(priv->dev, session->username);
|
||||||
if (prints == NULL) {
|
if (prints == NULL) {
|
||||||
@ -1053,7 +1047,6 @@ static gboolean fprint_device_verify_start (FprintDBusDevice *dbus_dev,
|
|||||||
} else {
|
} else {
|
||||||
finger_num = GPOINTER_TO_INT (prints->data);
|
finger_num = GPOINTER_TO_INT (prints->data);
|
||||||
}
|
}
|
||||||
g_slist_free(prints);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fp_device_supports_identify (priv->dev) && finger_num == -1) {
|
if (fp_device_supports_identify (priv->dev) && finger_num == -1) {
|
||||||
@ -1110,7 +1103,7 @@ static gboolean fprint_device_verify_stop (FprintDBusDevice *dbus_dev,
|
|||||||
g_autoptr(SessionData) session = NULL;
|
g_autoptr(SessionData) session = NULL;
|
||||||
FprintDevice *rdev = FPRINT_DEVICE (dbus_dev);
|
FprintDevice *rdev = FPRINT_DEVICE (dbus_dev);
|
||||||
FprintDevicePrivate *priv = fprint_device_get_instance_private(rdev);
|
FprintDevicePrivate *priv = fprint_device_get_instance_private(rdev);
|
||||||
GError *error = NULL;
|
g_autoptr(GError) error = NULL;
|
||||||
|
|
||||||
if (!_fprint_device_check_claimed (rdev, invocation, STATE_CLAIMED, &error)) {
|
if (!_fprint_device_check_claimed (rdev, invocation, STATE_CLAIMED, &error)) {
|
||||||
g_dbus_method_invocation_return_gerror (invocation, error);
|
g_dbus_method_invocation_return_gerror (invocation, error);
|
||||||
@ -1118,16 +1111,16 @@ static gboolean fprint_device_verify_stop (FprintDBusDevice *dbus_dev,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (priv->current_action == ACTION_NONE) {
|
if (priv->current_action == ACTION_NONE) {
|
||||||
g_set_error(&error, FPRINT_ERROR, FPRINT_ERROR_NO_ACTION_IN_PROGRESS,
|
g_dbus_method_invocation_return_error_literal (invocation,
|
||||||
|
FPRINT_ERROR,
|
||||||
|
FPRINT_ERROR_NO_ACTION_IN_PROGRESS,
|
||||||
"No verification in progress");
|
"No verification in progress");
|
||||||
g_dbus_method_invocation_return_gerror (invocation, error);
|
|
||||||
g_error_free (error);
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
} else if (priv->current_action == ACTION_ENROLL) {
|
} else if (priv->current_action == ACTION_ENROLL) {
|
||||||
g_set_error(&error, FPRINT_ERROR, FPRINT_ERROR_ALREADY_IN_USE,
|
g_dbus_method_invocation_return_error_literal (invocation,
|
||||||
|
FPRINT_ERROR,
|
||||||
|
FPRINT_ERROR_ALREADY_IN_USE,
|
||||||
"Enrollment in progress");
|
"Enrollment in progress");
|
||||||
g_dbus_method_invocation_return_gerror (invocation, error);
|
|
||||||
g_error_free (error);
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1180,7 +1173,8 @@ static gboolean try_delete_print(FprintDevice *rdev)
|
|||||||
|
|
||||||
for (user = users; user; user = user->next) {
|
for (user = users; user; user = user->next) {
|
||||||
const char *username = user->data;
|
const char *username = user->data;
|
||||||
GSList *fingers, *finger;
|
g_autoptr(GSList) fingers = NULL;
|
||||||
|
GSList *finger;
|
||||||
|
|
||||||
fingers = store.discover_prints (priv->dev, username);
|
fingers = store.discover_prints (priv->dev, username);
|
||||||
|
|
||||||
@ -1205,8 +1199,6 @@ static gboolean try_delete_print(FprintDevice *rdev)
|
|||||||
/* Found an equal print, remove it */
|
/* Found an equal print, remove it */
|
||||||
g_ptr_array_remove_index (device_prints, index);
|
g_ptr_array_remove_index (device_prints, index);
|
||||||
}
|
}
|
||||||
|
|
||||||
g_slist_free (fingers);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
g_slist_free_full (users, g_free);
|
g_slist_free_full (users, g_free);
|
||||||
@ -1230,14 +1222,18 @@ static gboolean try_delete_print(FprintDevice *rdev)
|
|||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if !GLIB_CHECK_VERSION (2, 63, 3)
|
||||||
|
G_DEFINE_AUTOPTR_CLEANUP_FUNC (GDate, g_date_free);
|
||||||
|
#endif
|
||||||
|
|
||||||
static FpPrint*
|
static FpPrint*
|
||||||
fprint_device_create_enroll_template(FprintDevice *rdev, gint finger_num)
|
fprint_device_create_enroll_template(FprintDevice *rdev, gint finger_num)
|
||||||
{
|
{
|
||||||
g_autoptr(SessionData) session = NULL;
|
g_autoptr(SessionData) session = NULL;
|
||||||
FprintDevicePrivate *priv = fprint_device_get_instance_private(rdev);
|
FprintDevicePrivate *priv = fprint_device_get_instance_private(rdev);
|
||||||
|
g_autoptr(GDateTime) datetime = NULL;
|
||||||
|
g_autoptr(GDate) date = NULL;
|
||||||
FpPrint *template = NULL;
|
FpPrint *template = NULL;
|
||||||
GDateTime *datetime = NULL;
|
|
||||||
GDate *date = NULL;
|
|
||||||
gint year, month, day;
|
gint year, month, day;
|
||||||
|
|
||||||
session = session_data_get (priv);
|
session = session_data_get (priv);
|
||||||
@ -1249,8 +1245,6 @@ fprint_device_create_enroll_template(FprintDevice *rdev, gint finger_num)
|
|||||||
g_date_time_get_ymd (datetime, &year, &month, &day);
|
g_date_time_get_ymd (datetime, &year, &month, &day);
|
||||||
date = g_date_new_dmy (day, month, year);
|
date = g_date_new_dmy (day, month, year);
|
||||||
fp_print_set_enroll_date (template, date);
|
fp_print_set_enroll_date (template, date);
|
||||||
g_date_free (date);
|
|
||||||
g_date_time_unref (datetime);
|
|
||||||
|
|
||||||
return template;
|
return template;
|
||||||
}
|
}
|
||||||
@ -1415,8 +1409,7 @@ static gboolean fprint_device_list_enrolled_fingers (FprintDBusDevice *dbus_dev,
|
|||||||
FprintDevice *rdev = FPRINT_DEVICE (dbus_dev);
|
FprintDevice *rdev = FPRINT_DEVICE (dbus_dev);
|
||||||
FprintDevicePrivate *priv = fprint_device_get_instance_private(rdev);
|
FprintDevicePrivate *priv = fprint_device_get_instance_private(rdev);
|
||||||
g_autoptr (GPtrArray) ret = NULL;
|
g_autoptr (GPtrArray) ret = NULL;
|
||||||
GError *error = NULL;
|
g_autoptr(GSList) prints = NULL;
|
||||||
GSList *prints;
|
|
||||||
GSList *item;
|
GSList *item;
|
||||||
const char *sender;
|
const char *sender;
|
||||||
const char *user;
|
const char *user;
|
||||||
@ -1429,10 +1422,10 @@ static gboolean fprint_device_list_enrolled_fingers (FprintDBusDevice *dbus_dev,
|
|||||||
prints = store.discover_prints(priv->dev, user);
|
prints = store.discover_prints(priv->dev, user);
|
||||||
|
|
||||||
if (!prints) {
|
if (!prints) {
|
||||||
g_set_error(&error, FPRINT_ERROR, FPRINT_ERROR_NO_ENROLLED_PRINTS,
|
g_dbus_method_invocation_return_error_literal (invocation,
|
||||||
|
FPRINT_ERROR,
|
||||||
|
FPRINT_ERROR_NO_ENROLLED_PRINTS,
|
||||||
"Failed to discover prints");
|
"Failed to discover prints");
|
||||||
g_dbus_method_invocation_return_gerror (invocation, error);
|
|
||||||
g_error_free (error);
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1443,8 +1436,6 @@ static gboolean fprint_device_list_enrolled_fingers (FprintDBusDevice *dbus_dev,
|
|||||||
}
|
}
|
||||||
g_ptr_array_add (ret, NULL);
|
g_ptr_array_add (ret, NULL);
|
||||||
|
|
||||||
g_slist_free(prints);
|
|
||||||
|
|
||||||
fprint_dbus_device_complete_list_enrolled_fingers (dbus_dev,
|
fprint_dbus_device_complete_list_enrolled_fingers (dbus_dev,
|
||||||
invocation, (const gchar *const *) ret->pdata);
|
invocation, (const gchar *const *) ret->pdata);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user