kernel-device-generic: plug memleak when processing platform ports

ptr_array_add_sysfs_attribute_link_basename() already reads the
current subsystem, so we should avoid overwriting the pointer.

  ==1630== 13 bytes in 2 blocks are definitely lost in loss record 270 of 3,092
  ==1630==    at 0x4842839: malloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
  ==1630==    by 0x4A1DDE8: g_malloc (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.6800.1)
  ==1630==    by 0x4A329E3: g_strdup (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.6800.1)
  ==1630==    by 0x26128E: ptr_array_add_sysfs_attribute_link_basename (mm-kernel-device-generic.c:244)
  ==1630==    by 0x263FD0: preload_contents_platform (mm-kernel-device-generic.c:314)
  ==1630==    by 0x263FD0: preload_contents (mm-kernel-device-generic.c:549)
  ==1630==    by 0x263FD0: check_preload (mm-kernel-device-generic.c:992)
  ==1630==    by 0x263FD0: initable_init (mm-kernel-device-generic.c:1139)
  ==1630==    by 0x4B6DDB9: g_initable_new_valist (in /usr/lib/x86_64-linux-gnu/libgio-2.0.so.0.6800.1)
  ==1630==    by 0x4B6DE6C: g_initable_new (in /usr/lib/x86_64-linux-gnu/libgio-2.0.so.0.6800.1)
  ==1630==    by 0x262087: mm_kernel_device_generic_new_with_rules (mm-kernel-device-generic.c:1054)
  ==1630==    by 0x17F66F: handle_kernel_event (mm-base-manager.c:689)
  ==1630==    by 0x17F7D2: report_kernel_event_auth_ready (mm-base-manager.c:1238)
  ==1630==    by 0x4BA37D8: ??? (in /usr/lib/x86_64-linux-gnu/libgio-2.0.so.0.6800.1)
  ==1630==    by 0x4BA3A1A: ??? (in /usr/lib/x86_64-linux-gnu/libgio-2.0.so.0.6800.1)
This commit is contained in:
Aleksander Morgado
2024-05-10 10:27:07 +00:00
parent 405e7a6012
commit e77c644ce2
@@ -314,7 +314,6 @@ preload_contents_platform (MMKernelDeviceGeneric *self,
ptr_array_add_sysfs_attribute_link_basename (subsystems, iter, "subsystem", &current_subsystem);
/* Take first parent with the given platform subsystem as physical device */
current_subsystem = read_sysfs_attribute_link_basename (iter, "subsystem");
if (!self->priv->physdev_sysfs_path && (g_strcmp0 (current_subsystem, platform) == 0)) {
self->priv->physdev_sysfs_path = g_strdup (iter);
/* stop traversing as soon as the physical device is found */