diff options
author | Beniamino Galvani <bgalvani@redhat.com> | 2018-06-27 09:13:42 +0200 |
---|---|---|
committer | Beniamino Galvani <bgalvani@redhat.com> | 2018-06-27 10:20:22 +0200 |
commit | cf0e60a1fe963f88716b13cd6408b83b88edc32f (patch) | |
tree | 859b59d516d282166913527a0993e4d6f54919f2 | |
parent | 5edaba96ff07c79768271e74e07fb6f74879158f (diff) | |
download | NetworkManager-cf0e60a1fe963f88716b13cd6408b83b88edc32f.tar.gz |
libnm-core: sink GVariants from nm_utils_parse_variant_attributes()
nm_utils_parse_variant_attributes() currently returns a GHashTable
containing floating GVariants, which are unreferenced when the hash
table is disposed. This API is inconvenient because:
- if the caller sinks the variants, the floating reference will be
converted to a full one, but this will not prevent the GVariant
from being disposed when the hash table is destroyed.
- if the caller refs the variants, this will add a new reference in
addition to the floating one, which is confusing because any
following g_variant_ref_sink() will probably do the wrong thing.
In other words the problem is that if the hash table owns the variant,
it should have a full reference to it. Fix this and improve the
function documentation.
Note that this changes behavior of a libnm public API. After
discussion we decided this is acceptable because the previous behavior
was a bug, and the documentation didn't specify that the returned
variants were floating. If anybody is using the function and upgrades
to a libnm version with this fix, the full reference instead of the
floating one could cause some leaks if the code did some assumptions
not justified by the function documentation.
https://bugzilla.redhat.com/show_bug.cgi?id=1594887
-rw-r--r-- | libnm-core/nm-utils.c | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/libnm-core/nm-utils.c b/libnm-core/nm-utils.c index b700c7f5fd..92cae1ab95 100644 --- a/libnm-core/nm-utils.c +++ b/libnm-core/nm-utils.c @@ -5990,7 +5990,8 @@ attribute_unescape (const char *start, const char *end) * Parse attributes from a string. * * Returns: (transfer full) (element-type utf8 GVariant): a #GHashTable mapping - * attribute names to #GVariant values. + * attribute names to #GVariant values. The #GHashTable holds a reference + * to each #GVariant that will be released when the hash table is disposed. * * Since: 1.8 */ @@ -6135,7 +6136,7 @@ nm_utils_parse_variant_attributes (const char *string, return NULL; } - g_hash_table_insert (ht, g_strdup ((*s)->name), variant); + g_hash_table_insert (ht, g_strdup ((*s)->name), g_variant_ref_sink (variant)); start = NULL; } next: |