file: simplify get_volume_name and fix leak

`g_mount_get_name` returns a freeable string, so there is no need to
duplicate it. Also use g_autoptr to simplify the function.
This commit is contained in:
Peter Eisenmann 2023-11-05 10:21:24 +01:00 committed by António Fernandes
parent f17fd617fb
commit f542b7fc84

View file

@ -7382,22 +7382,10 @@ nautilus_file_get_volume_free_space (NautilusFile *file)
char *
nautilus_file_get_volume_name (NautilusFile *file)
{
GFile *location;
char *res;
GMount *mount;
g_autoptr (GFile) location = nautilus_file_get_location (file);
g_autoptr (GMount) mount = g_file_find_enclosing_mount (location, NULL, NULL);
res = NULL;
location = nautilus_file_get_location (file);
mount = g_file_find_enclosing_mount (location, NULL, NULL);
if (mount)
{
res = g_strdup (g_mount_get_name (mount));
g_object_unref (mount);
}
g_object_unref (location);
return res;
return mount != NULL ? g_mount_get_name (mount) : NULL;
}
/**