examples: Fix possible use-after-free in storage code

The variant may need the buffer, so we should only free the buffer
together with the variant.
This commit is contained in:
Benjamin Berg 2020-01-02 18:38:19 +01:00
parent 19f239ce61
commit 36108f9f82

View file

@ -57,7 +57,7 @@ load_data (void)
{
GVariantDict *res;
GVariant *var;
g_autofree gchar *contents = NULL;
gchar *contents = NULL;
gsize length = 0;
if (!g_file_get_contents (STORAGE_FILE, &contents, &length, NULL))
@ -66,7 +66,12 @@ load_data (void)
return g_variant_dict_new (NULL);
}
var = g_variant_new_from_data (G_VARIANT_TYPE_VARDICT, contents, length, FALSE, NULL, NULL);
var = g_variant_new_from_data (G_VARIANT_TYPE_VARDICT,
contents,
length,
FALSE,
g_free,
contents);
res = g_variant_dict_new (var);
g_variant_unref (var);