mirror of
https://github.com/vlang/v.git
synced 2025-09-13 14:32:26 +03:00
crypto: add .free() and .reset() methods to reduce memory leaks with -autofree (#16992)
* Fix unsafe pointer I was compile vab with '-prod' and it was needed to fix and it is of course warning * Add files via upload * reduce memory leak s sha512 * add method .free() and .reset() for some
This commit is contained in:
parent
92fd12c18a
commit
6bf6a40e0c
13 changed files with 187 additions and 8 deletions
|
@ -70,9 +70,26 @@ mut:
|
|||
function crypto.Hash
|
||||
}
|
||||
|
||||
fn (mut d Digest) reset() {
|
||||
// free the resources taken by the Digest `d`
|
||||
[unsafe]
|
||||
pub fn (mut d Digest) free() {
|
||||
$if prealloc {
|
||||
return
|
||||
}
|
||||
unsafe {
|
||||
d.x.free()
|
||||
d.h.free()
|
||||
}
|
||||
}
|
||||
|
||||
fn (mut d Digest) init() {
|
||||
d.h = []u64{len: (8)}
|
||||
d.x = []u8{len: sha512.chunk}
|
||||
d.reset()
|
||||
}
|
||||
|
||||
// reset the state of the Digest `d`
|
||||
pub fn (mut d Digest) reset() {
|
||||
match d.function {
|
||||
.sha384 {
|
||||
d.h[0] = sha512.init0_384
|
||||
|
@ -124,7 +141,7 @@ fn new_digest(hash crypto.Hash) &Digest {
|
|||
mut d := &Digest{
|
||||
function: hash
|
||||
}
|
||||
d.reset()
|
||||
d.init()
|
||||
return d
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue