mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +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:
@@ -19,6 +19,19 @@ mut:
|
||||
tmp []u8
|
||||
}
|
||||
|
||||
// free the resources taken by the Cbc `x`
|
||||
[unsafe]
|
||||
pub fn (mut x Cbc) free() {
|
||||
$if prealloc {
|
||||
return
|
||||
}
|
||||
unsafe {
|
||||
// x.b.free() TODO add?
|
||||
x.iv.free()
|
||||
x.tmp.free()
|
||||
}
|
||||
}
|
||||
|
||||
// internal
|
||||
fn new_des_cbc(b Block, iv []u8) Cbc {
|
||||
return Cbc{
|
||||
|
||||
@@ -20,6 +20,19 @@ mut:
|
||||
decrypt bool
|
||||
}
|
||||
|
||||
// free the resources taken by the Cfb `x`
|
||||
[unsafe]
|
||||
pub fn (mut x Cfb) free() {
|
||||
$if prealloc {
|
||||
return
|
||||
}
|
||||
unsafe {
|
||||
// x.b.free() TODO add?
|
||||
x.out.free()
|
||||
x.next.free()
|
||||
}
|
||||
}
|
||||
|
||||
// new_cfb_encrypter returns a `Cfb` which encrypts with cipher feedback mode,
|
||||
// using the given Block. The iv must be the same length as the Block's block
|
||||
// size
|
||||
|
||||
@@ -21,6 +21,19 @@ mut:
|
||||
out_used int
|
||||
}
|
||||
|
||||
// free the resources taken by the Ctr `c`
|
||||
[unsafe]
|
||||
pub fn (mut x Ctr) free() {
|
||||
$if prealloc {
|
||||
return
|
||||
}
|
||||
unsafe {
|
||||
// x.b.free() TODO add?
|
||||
x.out.free()
|
||||
x.next.free()
|
||||
}
|
||||
}
|
||||
|
||||
// new_ctr returns a Ctr which encrypts/decrypts using the given Block in
|
||||
// counter mode. The length of iv must be the same as the Block's block size.
|
||||
pub fn new_ctr(b Block, iv []u8) Ctr {
|
||||
|
||||
Reference in New Issue
Block a user