mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2025-12-27 11:40:08 +01:00
platform: intern driver string for NMPlatformLink
Always intern string from udev_get_driver().
We use the result of udev_get_driver() for setting NMPlatformLink.driver.
In all other cases, we already set that value to an interned string,
which simplifies memory handling.
As it was, the lifetime of that string was tied to the lifetime of the
GUdevDevice.
This is not a stelar solution, but we assume that the overall numbers
of different drivers is limited so we don't leak large amounts of
memory.
(cherry picked from commit 3171b543dc)
This commit is contained in:
parent
efec4b42e2
commit
7b6ffb1e5f
3 changed files with 14 additions and 13 deletions
|
|
@ -455,7 +455,7 @@ udev_get_driver (GUdevDevice *device, int ifindex)
|
|||
|
||||
driver = g_udev_device_get_driver (device);
|
||||
if (driver)
|
||||
return driver;
|
||||
goto out;
|
||||
|
||||
/* Try the parent */
|
||||
parent = g_udev_device_get_parent (device);
|
||||
|
|
@ -470,23 +470,18 @@ udev_get_driver (GUdevDevice *device, int ifindex)
|
|||
if ( (g_strcmp0 (subsys, "ibmebus") == 0)
|
||||
|| (subsys == NULL)) {
|
||||
grandparent = g_udev_device_get_parent (parent);
|
||||
if (grandparent) {
|
||||
if (grandparent)
|
||||
driver = g_udev_device_get_driver (grandparent);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Intern the string so we don't have to worry about memory
|
||||
* management in NMPlatformLink.
|
||||
*/
|
||||
if (driver)
|
||||
driver = g_intern_string (driver);
|
||||
|
||||
g_clear_object (&parent);
|
||||
g_clear_object (&grandparent);
|
||||
|
||||
return driver;
|
||||
out:
|
||||
/* Intern the string so we don't have to worry about memory
|
||||
* management in NMPlatformLink. */
|
||||
return g_intern_string (driver);
|
||||
}
|
||||
|
||||
/******************************************************************
|
||||
|
|
|
|||
|
|
@ -2856,7 +2856,7 @@ nm_platform_link_cmp (const NMPlatformLink *a, const NMPlatformLink *b)
|
|||
_CMP_FIELD_BOOL (a, b, initialized);
|
||||
_CMP_FIELD_STR_INTERNED (a, b, kind);
|
||||
_CMP_FIELD_STR0 (a, b, udi);
|
||||
_CMP_FIELD_STR0 (a, b, driver);
|
||||
_CMP_FIELD_STR_INTERNED (a, b, driver);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -86,11 +86,17 @@ struct _NMPlatformLink {
|
|||
char name[IFNAMSIZ];
|
||||
NMLinkType type;
|
||||
|
||||
/* rtnl_link_get_type(), IFLA_INFO_KIND */
|
||||
/* rtnl_link_get_type(), IFLA_INFO_KIND. */
|
||||
/* NMPlatform initializes this field with a static string. */
|
||||
const char *kind;
|
||||
|
||||
/* Beware: NMPlatform initializes this string with an allocated string.
|
||||
* Handle it properly (i.e. don't keep a reference to it). */
|
||||
const char *udi;
|
||||
|
||||
/* NMPlatform initializes this field with a static string. */
|
||||
const char *driver;
|
||||
|
||||
gboolean initialized;
|
||||
int master;
|
||||
int parent;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue