diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2021-05-04 06:47:24 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2021-05-04 06:47:24 -0700 |
commit | 0c07bd4a499379c47916ce7cbf8d03af79e3aa98 (patch) | |
tree | 93f223db2e75262e024e2f84012241a67ec5211b /chksum.c | |
parent | 9a7f2d51807c182c7cb7e554c3be109ccd066ad8 (diff) | |
download | txr-0c07bd4a499379c47916ce7cbf8d03af79e3aa98.tar.gz txr-0c07bd4a499379c47916ce7cbf8d03af79e3aa98.tar.bz2 txr-0c07bd4a499379c47916ce7cbf8d03af79e3aa98.zip |
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.
Diffstat (limited to 'chksum.c')
-rw-r--r-- | chksum.c | 2 |
1 files changed, 1 insertions, 1 deletions
@@ -97,7 +97,7 @@ static val chksum_ensure_buf(val self, val buf_in, { if (null_or_missing_p(buf_in)) { *phash = chk_malloc(c_unum(len, self)); - return make_borrowed_buf(len, *phash); + return make_owned_buf(len, *phash); } else { *phash = buf_get(buf_in, self); if (lt(length_buf(buf_in), len)) |