Thanks to Matthias Andree's debugging, it appears the cert is not
freed when PEM_read_X509() encounters EOF. Change the return value
check to not overwrite cert. It is already updated via the second
parameter.
return 0;
}
- while ((cert = PEM_read_X509 (fp, &cert, NULL, NULL)) != NULL)
+ while (PEM_read_X509 (fp, &cert, NULL, NULL) != NULL)
{
pass = compare_certificates (cert, peercert, peermd, peermdlen) ? 0 : 1;