summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Catanzaro <mcatanzaro@igalia.com>2019-06-22 13:23:09 -0500
committerMichael Catanzaro <mcatanzaro@igalia.com>2019-06-22 13:23:09 -0500
commit0d03b2c6dc062b7682163ef7f279dfb0b010264d (patch)
treeeef49df7b46de695e9073077480352b76e4b8581
parenta6f0eadb51aae5351a0cfd6b9da3dcba6b134e1a (diff)
downloadgvdb-0d03b2c6dc062b7682163ef7f279dfb0b010264d.tar.gz
Don't free FileBuilder in serialize function
It's confused both myself and Jan-Michael, when reviewing my changes to this code. It's weird for the serialize function to take ownership of the passed FileBuilder. Don't do that. We can also add a convenience free function.
-rw-r--r--gvdb-builder.c12
1 files changed, 9 insertions, 3 deletions
diff --git a/gvdb-builder.c b/gvdb-builder.c
index 70c0ac1..cf94691 100644
--- a/gvdb-builder.c
+++ b/gvdb-builder.c
@@ -450,6 +450,13 @@ file_builder_new (gboolean byteswap)
return builder;
}
+static void
+file_builder_free (FileBuilder *fb)
+{
+ g_queue_free (fb->chunks);
+ g_slice_free (FileBuilder, fb);
+}
+
static GString *
file_builder_serialise (FileBuilder *fb,
struct gvdb_pointer root)
@@ -494,9 +501,6 @@ file_builder_serialise (FileBuilder *fb,
g_slice_free (FileChunk, chunk);
}
- g_queue_free (fb->chunks);
- g_slice_free (FileBuilder, fb);
-
return result;
}
@@ -518,6 +522,7 @@ gvdb_table_write_contents (GHashTable *table,
fb = file_builder_new (byteswap);
file_builder_add_hash (fb, table, &root);
str = file_builder_serialise (fb, root);
+ file_builder_free (fb);
status = g_file_set_contents (filename, str->str, str->len, error);
g_string_free (str, TRUE);
@@ -594,6 +599,7 @@ gvdb_table_write_contents_async (GHashTable *table,
file_builder_add_hash (fb, table, &root);
str = file_builder_serialise (fb, root);
bytes = g_string_free_to_bytes (str);
+ file_builder_free (fb);
file = g_file_new_for_path (filename);
data = write_contents_data_new (bytes, file);