Skip to content

Commit

Permalink
examples/echo: free allocated memory when an error happens
Browse files Browse the repository at this point in the history
If either `priv_key` or `pub_key` is `NULL` but not the other one, the
allocated memory is not freed. This issue is reported by clang's static
analyzer.

Fix this by calling `noise_free` in the error block.
  • Loading branch information
niooss-ledger committed Jul 2, 2021
1 parent 1758c27 commit 6cde834
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions examples/echo/echo-keygen/echo-keygen.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ int main(int argc, char *argv[])
pub_key = (uint8_t *)malloc(pub_key_len);
if (!priv_key || !pub_key) {
fprintf(stderr, "Out of memory\n");
noise_free(priv_key, priv_key_len);
noise_free(pub_key, pub_key_len);
noise_dhstate_free(dh);
return 1;
}
err = noise_dhstate_get_keypair
Expand Down

0 comments on commit 6cde834

Please sign in to comment.