From 0c07bd4a499379c47916ce7cbf8d03af79e3aa98 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Tue, 4 May 2021 06:47:24 -0700 Subject: sha256/md5: leak: don't use borrowed buffer for hash. It's incorrect to use a borrowed buf, because a borrowed buf assumes that the memory isn't dynamically allocated, and will not free it when it is finalized by the garbage collector. The buffer which holds the hash returned by sha256 and md5 does in fact own the memory. * buf.c (make_owned_buf): Static function becomes external. * buf.h (make_owned_buf): Declared. * chksum.c (chksum_ensure_buf): Use make_owned_buf rather than make_borrowed_buf. --- buf.h | 1 + 1 file changed, 1 insertion(+) (limited to 'buf.h') diff --git a/buf.h b/buf.h index 683d5438..1805f3b8 100644 --- a/buf.h +++ b/buf.h @@ -29,6 +29,7 @@ val make_buf(val len, val init_val, val alloc_size); val bufp(val object); val make_borrowed_buf(val len, mem_t *data); val init_borrowed_buf(obj_t *buf, val len, mem_t *data); +val make_owned_buf(val len, mem_t *data); val make_duplicate_buf(val len, mem_t *data); val copy_buf(val buf); val buf_trim(val buf); -- cgit v1.2.3