After calling mbedtls_x509_crt_parse() is it safe to free the certificate buffer

Hi,
After calling mbedtls_x509_crt_parse() to parse a certificate is it safe to free the buffer?

The variable buf holds a certificate, but after it’s parsed I want to free up some memory so I want to know if the parsing using the original buffer or makes a copy of the data.

Thanks

Hi,
As you can see in the code, when parsing a certificate, the library allocates memory, for the certificate raw data, to be kept in the certificate context. There are no assumptions on the input buffer, whether it is a stack variable or a heap variable.
Regards,
Mbed TLS Team member
Ron