Skip to content

Commit

Permalink
Free psa crypto at the end of programs when initialized
Browse files Browse the repository at this point in the history
Signed-off-by: Przemek Stekiel <[email protected]>
  • Loading branch information
mprse committed Apr 25, 2023
1 parent af48f3c commit c4ddf92
Show file tree
Hide file tree
Showing 15 changed files with 21 additions and 13 deletions.
2 changes: 1 addition & 1 deletion programs/ssl/dtls_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -334,12 +334,12 @@ int main(int argc, char *argv[])
#endif

mbedtls_net_free(&server_fd);

mbedtls_x509_crt_free(&cacert);
mbedtls_ssl_free(&ssl);
mbedtls_ssl_config_free(&conf);
mbedtls_ctr_drbg_free(&ctr_drbg);
mbedtls_entropy_free(&entropy);
mbedtls_psa_crypto_free();

#if defined(_WIN32)
mbedtls_printf(" + Press Enter to exit this program.\n");
Expand Down
1 change: 1 addition & 0 deletions programs/ssl/dtls_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,7 @@ int main(void)
#endif
mbedtls_ctr_drbg_free(&ctr_drbg);
mbedtls_entropy_free(&entropy);
mbedtls_psa_crypto_free();

#if defined(_WIN32)
printf(" Press Enter to exit this program.\n");
Expand Down
2 changes: 1 addition & 1 deletion programs/ssl/mini_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -274,14 +274,14 @@ int main(void)

exit:
mbedtls_net_free(&server_fd);

mbedtls_ssl_free(&ssl);
mbedtls_ssl_config_free(&conf);
mbedtls_ctr_drbg_free(&ctr_drbg);
mbedtls_entropy_free(&entropy);
#if defined(MBEDTLS_X509_CRT_PARSE_C)
mbedtls_x509_crt_free(&ca);
#endif
mbedtls_psa_crypto_free();

mbedtls_exit(ret);
}
Expand Down
2 changes: 1 addition & 1 deletion programs/ssl/ssl_client1.c
Original file line number Diff line number Diff line change
Expand Up @@ -284,12 +284,12 @@ int main(void)
#endif

mbedtls_net_free(&server_fd);

mbedtls_x509_crt_free(&cacert);
mbedtls_ssl_free(&ssl);
mbedtls_ssl_config_free(&conf);
mbedtls_ctr_drbg_free(&ctr_drbg);
mbedtls_entropy_free(&entropy);
mbedtls_psa_crypto_free();

#if defined(_WIN32)
mbedtls_printf(" + Press Enter to exit this program.\n");
Expand Down
2 changes: 2 additions & 0 deletions programs/ssl/ssl_context_info.c
Original file line number Diff line number Diff line change
Expand Up @@ -1017,6 +1017,8 @@ int main(int argc, char *argv[])
printf("Finished. No valid base64 code found\n");
}

mbedtls_psa_crypto_free();

return 0;
}

Expand Down
2 changes: 1 addition & 1 deletion programs/ssl/ssl_fork_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -378,13 +378,13 @@ int main(void)
exit:
mbedtls_net_free(&client_fd);
mbedtls_net_free(&listen_fd);

mbedtls_x509_crt_free(&srvcert);
mbedtls_pk_free(&pkey);
mbedtls_ssl_free(&ssl);
mbedtls_ssl_config_free(&conf);
mbedtls_ctr_drbg_free(&ctr_drbg);
mbedtls_entropy_free(&entropy);
mbedtls_psa_crypto_free();

#if defined(_WIN32)
mbedtls_printf(" Press Enter to exit this program.\n");
Expand Down
1 change: 1 addition & 0 deletions programs/ssl/ssl_mail_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -801,6 +801,7 @@ int main(int argc, char *argv[])
mbedtls_ssl_config_free(&conf);
mbedtls_ctr_drbg_free(&ctr_drbg);
mbedtls_entropy_free(&entropy);
mbedtls_psa_crypto_free();

#if defined(_WIN32)
mbedtls_printf(" + Press Enter to exit this program.\n");
Expand Down
4 changes: 1 addition & 3 deletions programs/ssl/ssl_pthread_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -487,14 +487,12 @@ int main(void)
mbedtls_ctr_drbg_free(&ctr_drbg);
mbedtls_entropy_free(&entropy);
mbedtls_ssl_config_free(&conf);

mbedtls_net_free(&listen_fd);

mbedtls_mutex_free(&debug_mutex);

#if defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C)
mbedtls_memory_buffer_alloc_free();
#endif
mbedtls_psa_crypto_free();

#if defined(_WIN32)
mbedtls_printf(" Press Enter to exit this program.\n");
Expand Down
2 changes: 1 addition & 1 deletion programs/ssl/ssl_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,6 @@ int main(void)

mbedtls_net_free(&client_fd);
mbedtls_net_free(&listen_fd);

mbedtls_x509_crt_free(&srvcert);
mbedtls_pk_free(&pkey);
mbedtls_ssl_free(&ssl);
Expand All @@ -367,6 +366,7 @@ int main(void)
#endif
mbedtls_ctr_drbg_free(&ctr_drbg);
mbedtls_entropy_free(&entropy);
mbedtls_psa_crypto_free();

#if defined(_WIN32)
mbedtls_printf(" Press Enter to exit this program.\n");
Expand Down
1 change: 1 addition & 0 deletions programs/x509/cert_app.c
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,7 @@ int main(int argc, char *argv[])
#endif
mbedtls_ctr_drbg_free(&ctr_drbg);
mbedtls_entropy_free(&entropy);
mbedtls_psa_crypto_free();

#if defined(_WIN32)
mbedtls_printf(" + Press Enter to exit this program.\n");
Expand Down
1 change: 1 addition & 0 deletions programs/x509/cert_req.c
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,7 @@ int main(int argc, char *argv[])
mbedtls_pk_free(&key);
mbedtls_ctr_drbg_free(&ctr_drbg);
mbedtls_entropy_free(&entropy);
mbedtls_psa_crypto_free();

#if defined(_WIN32)
mbedtls_printf(" + Press Enter to exit this program.\n");
Expand Down
1 change: 1 addition & 0 deletions programs/x509/cert_write.c
Original file line number Diff line number Diff line change
Expand Up @@ -726,6 +726,7 @@ int main(int argc, char *argv[])
mbedtls_mpi_free(&serial);
mbedtls_ctr_drbg_free(&ctr_drbg);
mbedtls_entropy_free(&entropy);
mbedtls_psa_crypto_free();

#if defined(_WIN32)
mbedtls_printf(" + Press Enter to exit this program.\n");
Expand Down
1 change: 1 addition & 0 deletions programs/x509/crl_app.c
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ int main(int argc, char *argv[])

exit:
mbedtls_x509_crl_free(&crl);
mbedtls_psa_crypto_free();

#if defined(_WIN32)
mbedtls_printf(" + Press Enter to exit this program.\n");
Expand Down
11 changes: 6 additions & 5 deletions programs/x509/load_roots.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,6 @@ int main(int argc, char *argv[])
struct mbedtls_timing_hr_time timer;
unsigned long ms;

if (argc <= 1) {
mbedtls_printf(USAGE);
goto exit;
}

#if defined(MBEDTLS_USE_PSA_CRYPTO)
psa_status_t status = psa_crypto_init();
if (status != PSA_SUCCESS) {
Expand All @@ -141,6 +136,11 @@ int main(int argc, char *argv[])
}
#endif /* MBEDTLS_USE_PSA_CRYPTO */

if (argc <= 1) {
mbedtls_printf(USAGE);
goto exit;
}

opt.filenames = NULL;
opt.iterations = DFL_ITERATIONS;
opt.prime_cache = DFL_PRIME_CACHE;
Expand Down Expand Up @@ -200,6 +200,7 @@ int main(int argc, char *argv[])
exit_code = MBEDTLS_EXIT_SUCCESS;

exit:
mbedtls_psa_crypto_free();
mbedtls_exit(exit_code);
}
#endif /* necessary configuration */
1 change: 1 addition & 0 deletions programs/x509/req_app.c
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ int main(int argc, char *argv[])

exit:
mbedtls_x509_csr_free(&csr);
mbedtls_psa_crypto_free();

#if defined(_WIN32)
mbedtls_printf(" + Press Enter to exit this program.\n");
Expand Down

0 comments on commit c4ddf92

Please sign in to comment.