mirror of
https://gitlab.freedesktop.org/upower/upower.git
synced 2026-05-19 15:28:12 +02:00
up: fix alloc memory on heap is redundant
affected function: - up_device_get_id - up_daemon_enum_devices - up_daemon_enum_kbd_backlights
This commit is contained in:
parent
25303ba527
commit
ed4280b51b
2 changed files with 21 additions and 18 deletions
|
|
@ -474,28 +474,29 @@ up_daemon_enumerate_devices (UpExportedDaemon *skeleton,
|
|||
{
|
||||
guint i;
|
||||
GPtrArray *array;
|
||||
GPtrArray *object_paths;
|
||||
UpDevice *device;
|
||||
const gchar **object_paths;
|
||||
guint num_devices;
|
||||
|
||||
/* build a pointer array of the object paths */
|
||||
object_paths = g_ptr_array_new_with_free_func (g_free);
|
||||
array = up_device_list_get_array (daemon->priv->power_devices);
|
||||
num_devices = array->len;
|
||||
object_paths = g_newa (const gchar *, num_devices + 1);
|
||||
num_devices = 0;
|
||||
for (i = 0; i < array->len; i++) {
|
||||
const char *object_path;
|
||||
const gchar *object_path;
|
||||
device = (UpDevice *) g_ptr_array_index (array, i);
|
||||
object_path = up_device_get_object_path (device);
|
||||
if (object_path != NULL)
|
||||
g_ptr_array_add (object_paths, g_strdup (object_path));
|
||||
object_paths[num_devices++] = object_path;
|
||||
}
|
||||
object_paths[num_devices] = NULL;
|
||||
g_ptr_array_unref (array);
|
||||
g_ptr_array_add (object_paths, NULL);
|
||||
|
||||
/* return it on the bus */
|
||||
up_exported_daemon_complete_enumerate_devices (skeleton, invocation,
|
||||
(const gchar **) object_paths->pdata);
|
||||
object_paths);
|
||||
|
||||
/* free */
|
||||
g_ptr_array_unref (object_paths);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
|
@ -506,28 +507,29 @@ up_daemon_enumerate_kbd_backlights (UpExportedDaemon *skeleton,
|
|||
{
|
||||
guint i;
|
||||
GPtrArray *array;
|
||||
GPtrArray *object_paths;
|
||||
UpDeviceKbdBacklight *kbd_backlight;
|
||||
const gchar **object_paths;
|
||||
guint num_devices;
|
||||
|
||||
/* build a pointer array of the object paths */
|
||||
object_paths = g_ptr_array_new_with_free_func (g_free);
|
||||
array = up_device_list_get_array (daemon->priv->kbd_backlight_devices);
|
||||
num_devices = array->len;
|
||||
object_paths = g_newa (const gchar *, num_devices + 1);
|
||||
num_devices = 0;
|
||||
for (i = 0; i < array->len; i++) {
|
||||
const char *object_path;
|
||||
const gchar *object_path;
|
||||
kbd_backlight = (UpDeviceKbdBacklight *) g_ptr_array_index (array, i);
|
||||
object_path = up_device_kbd_backlight_get_object_path (kbd_backlight);
|
||||
if (object_path != NULL)
|
||||
g_ptr_array_add (object_paths, g_strdup (object_path));
|
||||
object_paths[num_devices++] = object_path;
|
||||
}
|
||||
object_paths[num_devices] = NULL;
|
||||
g_ptr_array_unref (array);
|
||||
g_ptr_array_add (object_paths, NULL);
|
||||
|
||||
/* return it on the bus */
|
||||
up_exported_daemon_complete_enumerate_kbd_backlights (skeleton, invocation,
|
||||
(const gchar **) object_paths->pdata);
|
||||
object_paths);
|
||||
|
||||
/* free */
|
||||
g_ptr_array_unref (object_paths);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -309,6 +309,7 @@ up_device_get_id (UpDevice *device)
|
|||
const char *model;
|
||||
const char *serial;
|
||||
UpExportedDevice *skeleton;
|
||||
char string_buf[256];
|
||||
|
||||
if (priv->native == NULL)
|
||||
return NULL;
|
||||
|
|
@ -325,7 +326,7 @@ up_device_get_id (UpDevice *device)
|
|||
if (!up_exported_device_get_is_present (skeleton))
|
||||
goto out;
|
||||
|
||||
string = g_string_new ("");
|
||||
string = g_string_new_len (string_buf, sizeof (string_buf));
|
||||
|
||||
/* in an ideal world, model-capacity-serial */
|
||||
if (model != NULL && strlen (model) > 2) {
|
||||
|
|
@ -355,7 +356,7 @@ up_device_get_id (UpDevice *device)
|
|||
|
||||
} else {
|
||||
/* generic fallback, get what data we can */
|
||||
string = g_string_new ("");
|
||||
string = g_string_new_len (string_buf, sizeof (string_buf));
|
||||
if (up_exported_device_get_vendor (skeleton) != NULL) {
|
||||
g_string_append (string, up_exported_device_get_vendor (skeleton));
|
||||
g_string_append_c (string, '-');
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue