diff --git a/src/bitwriter.c b/src/bitwriter.c
index f307caa24585723ae8886093b19ee8ecb59799ac..a3d6c15b8a77c4e7d2d13e319c5bceb2085ffd92 100644
--- a/src/bitwriter.c
+++ b/src/bitwriter.c
@@ -88,6 +88,19 @@ void h_bit_writer_put(HBitWriter* w, unsigned long long data, size_t nbits) {
 }
 
 
-uint8_t *h_bit_writer_get_buffer(HBitWriter* w, size_t *len);
+const uint8_t *h_bit_writer_get_buffer(HBitWriter* w, size_t *len) {
+  assert (len != NULL);
+  assert (w != NULL);
+  // Not entirely sure how to handle a non-integral number of bytes... make it an error for now
+  assert (w->bit_offset == 0); // BUG: change this to some sane behaviour
+
+  *len = w->index;
+  return w->buf
+}
+
+void h_bit_writer_free(HBitWriter* w) {
+  g_free(w->buf);
+  g_free(w);
+}
 
 // TESTS BELOW HERE
diff --git a/src/hammer.h b/src/hammer.h
index 8df48a8cd407c7a9c7c79d9173d974efd7e480b6..26367f30d816d591e9d2fe683f677f9570420f22 100644
--- a/src/hammer.h
+++ b/src/hammer.h
@@ -470,7 +470,7 @@ void h_bit_writer_put(HBitWriter* w, unsigned long long data, size_t nbits);
  * Must not free [w] until you're done with the result.
  * [len] is in bytes.
  */
-uint8_t *h_bit_writer_get_buffer(HBitWriter* w, size_t *len);
+const uint8_t *h_bit_writer_get_buffer(HBitWriter* w, size_t *len);
 
 /**
  * TODO: Document me