Free psa crypto at the end of programs when initialized

Signed-off-by: Przemek Stekiel <przemyslaw.stekiel@mobica.com>
This commit is contained in:
Przemek Stekiel 2023-04-19 10:15:26 +02:00
parent e296868b25
commit a8c560a799
15 changed files with 21 additions and 13 deletions

View file

@ -334,12 +334,12 @@ exit:
#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();
/* Shell can not handle large exit numbers -> 1 for errors */
if (ret < 0) {

View file

@ -404,6 +404,7 @@ exit:
#endif
mbedtls_ctr_drbg_free(&ctr_drbg);
mbedtls_entropy_free(&entropy);
mbedtls_psa_crypto_free();
/* Shell can not handle large exit numbers -> 1 for errors */
if (ret < 0) {

View file

@ -270,7 +270,6 @@ int main(void)
exit:
mbedtls_net_free(&server_fd);
mbedtls_ssl_free(&ssl);
mbedtls_ssl_config_free(&conf);
mbedtls_ctr_drbg_free(&ctr_drbg);
@ -278,6 +277,7 @@ exit:
#if defined(MBEDTLS_X509_CRT_PARSE_C)
mbedtls_x509_crt_free(&ca);
#endif
mbedtls_psa_crypto_free();
mbedtls_exit(ret);
}

View file

@ -284,12 +284,12 @@ exit:
#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();
mbedtls_exit(exit_code);
}

View file

@ -1011,6 +1011,8 @@ int main(int argc, char *argv[])
printf("Finished. No valid base64 code found\n");
}
mbedtls_psa_crypto_free();
return 0;
}

View file

@ -375,13 +375,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();
mbedtls_exit(exit_code);
}

View file

@ -805,6 +805,7 @@ exit:
mbedtls_ssl_config_free(&conf);
mbedtls_ctr_drbg_free(&ctr_drbg);
mbedtls_entropy_free(&entropy);
mbedtls_psa_crypto_free();
mbedtls_exit(exit_code);
}

View file

@ -483,14 +483,12 @@ exit:
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();
mbedtls_exit(ret);
}

View file

@ -353,7 +353,6 @@ exit:
mbedtls_net_free(&client_fd);
mbedtls_net_free(&listen_fd);
mbedtls_x509_crt_free(&srvcert);
mbedtls_pk_free(&pkey);
mbedtls_ssl_free(&ssl);
@ -363,6 +362,7 @@ exit:
#endif
mbedtls_ctr_drbg_free(&ctr_drbg);
mbedtls_entropy_free(&entropy);
mbedtls_psa_crypto_free();
mbedtls_exit(ret);
}

View file

@ -457,6 +457,7 @@ exit:
#endif
mbedtls_ctr_drbg_free(&ctr_drbg);
mbedtls_entropy_free(&entropy);
mbedtls_psa_crypto_free();
mbedtls_exit(exit_code);
}

View file

@ -469,6 +469,7 @@ exit:
mbedtls_pk_free(&key);
mbedtls_ctr_drbg_free(&ctr_drbg);
mbedtls_entropy_free(&entropy);
mbedtls_psa_crypto_free();
cur = opt.san_list;
while (cur != NULL) {

View file

@ -894,6 +894,7 @@ exit:
mbedtls_pk_free(&loaded_issuer_key);
mbedtls_ctr_drbg_free(&ctr_drbg);
mbedtls_entropy_free(&entropy);
mbedtls_psa_crypto_free();
mbedtls_exit(exit_code);
}

View file

@ -134,6 +134,7 @@ usage:
exit:
mbedtls_x509_crl_free(&crl);
mbedtls_psa_crypto_free();
mbedtls_exit(exit_code);
}

View file

@ -123,11 +123,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) {
@ -137,6 +132,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;
@ -196,6 +196,7 @@ int main(int argc, char *argv[])
exit_code = MBEDTLS_EXIT_SUCCESS;
exit:
mbedtls_psa_crypto_free();
mbedtls_exit(exit_code);
}
#endif /* necessary configuration */

View file

@ -134,6 +134,7 @@ usage:
exit:
mbedtls_x509_csr_free(&csr);
mbedtls_psa_crypto_free();
mbedtls_exit(exit_code);
}