mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-08-01 10:06:53 +03:00
pkwrite.c: call calloc and free properly
Signed-off-by: Yanray Wang <yanray.wang@arm.com>
This commit is contained in:
@ -572,7 +572,7 @@ int mbedtls_pk_write_pubkey_pem(mbedtls_pk_context *key, unsigned char *buf, siz
|
|||||||
{
|
{
|
||||||
int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
|
int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
|
||||||
unsigned char *output_buf = NULL;
|
unsigned char *output_buf = NULL;
|
||||||
output_buf = calloc(1, PUB_DER_MAX_BYTES);
|
output_buf = mbedtls_calloc(1, PUB_DER_MAX_BYTES);
|
||||||
if (output_buf == NULL) {
|
if (output_buf == NULL) {
|
||||||
return MBEDTLS_ERR_PK_ALLOC_FAILED;
|
return MBEDTLS_ERR_PK_ALLOC_FAILED;
|
||||||
}
|
}
|
||||||
@ -594,7 +594,7 @@ int mbedtls_pk_write_pubkey_pem(mbedtls_pk_context *key, unsigned char *buf, siz
|
|||||||
|
|
||||||
ret = 0;
|
ret = 0;
|
||||||
cleanup:
|
cleanup:
|
||||||
free(output_buf);
|
mbedtls_free(output_buf);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -602,7 +602,7 @@ int mbedtls_pk_write_key_pem(mbedtls_pk_context *key, unsigned char *buf, size_t
|
|||||||
{
|
{
|
||||||
int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
|
int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
|
||||||
unsigned char *output_buf = NULL;
|
unsigned char *output_buf = NULL;
|
||||||
output_buf = calloc(1, PRV_DER_MAX_BYTES);
|
output_buf = mbedtls_calloc(1, PRV_DER_MAX_BYTES);
|
||||||
if (output_buf == NULL) {
|
if (output_buf == NULL) {
|
||||||
return MBEDTLS_ERR_PK_ALLOC_FAILED;
|
return MBEDTLS_ERR_PK_ALLOC_FAILED;
|
||||||
}
|
}
|
||||||
@ -641,7 +641,7 @@ int mbedtls_pk_write_key_pem(mbedtls_pk_context *key, unsigned char *buf, size_t
|
|||||||
|
|
||||||
ret = 0;
|
ret = 0;
|
||||||
cleanup:
|
cleanup:
|
||||||
free(output_buf);
|
mbedtls_free(output_buf);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
#endif /* MBEDTLS_PEM_WRITE_C */
|
#endif /* MBEDTLS_PEM_WRITE_C */
|
||||||
|
Reference in New Issue
Block a user