Plug memory leaks in kx_ functions

If we, for some reason, fail to the error-path, then binaries allocated
are not being released properly back to the erlang runtime. Fix this
in the usual fashion by using a stack of undo-operations, and thread
them via goto.
This commit is contained in:
Jesper Louis Andersen
2020-01-21 13:01:48 +01:00
parent d850b16d1b
commit 899fbeefd3
2 changed files with 78 additions and 27 deletions
+11 -1
View File
@@ -43,7 +43,8 @@ groups() ->
aead_xchacha20poly1305,
aead_chacha20poly1305,
pwhash,
sign]},
sign,
kx]},
[Neg, Pos].
@@ -139,3 +140,12 @@ sign_chunked(S, M, N) ->
S2 = enacl:sign_update(S, M),
sign_chunked(S2, M, N-1).
kx(_Config) ->
#{ public := CPK, secret := CSK} = enacl:kx_keypair(),
#{ public := SPK, secret := SSK} = enacl:kx_keypair(),
#{ client_tx := CTX, client_rx := CRX} = enacl:kx_client_session_keys(CPK, CSK, SPK),
#{ server_tx := STX, server_rx := SRX} = enacl:kx_server_session_keys(SPK, SSK, CPK),
%% Verify we got a shared keypair
CTX = SRX,
STX = CRX,
ok.