From e59847ca99c13eb61ab330226336839ed12289bd Mon Sep 17 00:00:00 2001 From: Nicolas Iooss Date: Thu, 17 Jun 2021 17:57:54 +0200 Subject: [PATCH] examples/echo: free allocated memory when an error happens 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. --- examples/echo/echo-keygen/echo-keygen.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/examples/echo/echo-keygen/echo-keygen.c b/examples/echo/echo-keygen/echo-keygen.c index bfb0bb94..e77f6012 100644 --- a/examples/echo/echo-keygen/echo-keygen.c +++ b/examples/echo/echo-keygen/echo-keygen.c @@ -80,6 +80,8 @@ 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); return 1; } err = noise_dhstate_get_keypair