Skip to content

Commit

Permalink
samples: psa_tls: Fix resource leak error
Browse files Browse the repository at this point in the history
In case psa_tls_send_buffer fails break ended the while loop without
closing the socket, which is a potential resource leak and causes
a coverity warning.
Also this way didn't allow any reconnect try, therefore changed the code
to not stoop the processing loop and just make the logging output
conditional

Signed-off-by: Markus Swarowsky <[email protected]>
  • Loading branch information
mswarowsky authored and cvinayak committed Dec 4, 2023
1 parent 8ea60c7 commit f620e5b
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions samples/crypto/psa_tls/src/psa_dtls_functions_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -147,11 +147,10 @@ void process_psa_tls(void)
ret = psa_tls_send_buffer(sock, recv_buffer, received);
if (ret != 0) {
LOG_ERR("DTLS Failed to send. Err: %d", errno);
break;
} else {
LOG_INF("DTLS replied with %d bytes", received);
LOG_INF("Closing DTLS connection");
}

LOG_INF("DTLS replied with %d bytes", received);
LOG_INF("Closing DTLS connection");
}

(void)close(sock);
Expand Down

0 comments on commit f620e5b

Please sign in to comment.