Ufx*_*Ufx 2 c string free openssl
我试图使用一个简单的SSL示例.
这是一些代码:
void ShowCerts(SSL* ssl)
{
X509 *cert;
char *line;
cert = SSL_get_peer_certificate(ssl); /* get the server's certificate */
if ( cert != NULL )
{
printf("Server certificates:\n");
line = X509_NAME_oneline(X509_get_subject_name(cert), 0, 0);
printf("Subject: %s\n", line);
free(line); /* free the malloc'ed string */
line = X509_NAME_oneline(X509_get_issuer_name(cert), 0, 0);
printf("Issuer: %s\n", line);
free(line); /* free the malloc'ed string */
X509_free(cert); /* free the malloc'ed certificate copy */
}
else
printf("No certificates.\n");
}
Run Code Online (Sandbox Code Playgroud)
程序在free(line)代码行中崩溃.没有这些行,该程序可以正常运行而不会崩溃.如果我删除这些行,我担心在这种情况下,某些已分配的资源将不会被释放 - 我该怎么办?
谢谢.