Skip to content

Commit 9284ed3

Browse files
jlebonppisar
authored andcommitted
Don't call g_variant_store() with NULL
A GVariant may require 0 bytes to serialize. In which case, `data_size` will be 0 and we'll call `g_malloc0 (0)` which returns `NULL`. The `data` argument of `g_variant_store` is declared as non-nullable, so we shouldn't pass it `NULL`. In older glib versions, this wasn't explicitly checked and it still transparently worked for our case because there was nothing to actually serialize. Starting from v2.84.1, a precondition was added: https://gitlab.gnome.org/GNOME/glib/-/commit/39c05b13123b12622ee2c93c170dbf20b573f6ac Let's respect the API here and stop calling the function if it's not needed. Note that `g_variant_new_from_data()` supports being passed `NULL` and 0 for the data and size arguments.
1 parent c6ffc06 commit 9284ed3

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

modulemd/modulemd-util.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -363,9 +363,13 @@ modulemd_variant_deep_copy (GVariant *variant)
363363
{
364364
const GVariantType *data_type = g_variant_get_type (variant);
365365
gsize data_size = g_variant_get_size (variant);
366-
gpointer data = g_malloc0 (data_size);
366+
gpointer data = NULL;
367367

368-
g_variant_store (variant, data);
368+
if (data_size > 0)
369+
{
370+
data = g_malloc0 (data_size);
371+
g_variant_store (variant, data);
372+
}
369373

370374
return g_variant_ref_sink (g_variant_new_from_data (
371375
data_type, data, data_size, FALSE, destroy_variant_data, data));

0 commit comments

Comments
 (0)