On Mon, 2013-02-18 at 13:22 +0100, Dr. Stephen Henson wrote: > Here's what's happening in detail. If you pass a non-NULL pointer for > the > second parameter it will attempt to reuse the structure. > > In the case of the RSA structure the outer (RSA *) is allocated via > OPENSSL_malloc and so are many internal structures (e.g. BIGNUM key > components), which it will also attempt to reuse. So all the internals > need to > be initialised to something sensible too or it may attempt to free up > unintialised pointers with unpredictable results. >
That makes perfect sense, thank you. > Where possible applications shouldn't mess around at this level. There > are > utility functions of the form X509_new (and RSA_new for (RSA *)) that > allocate > and initialise the structures correctly. > > So you could do something like this: > > RSA *prsa1, *prsa2; > > prsa1 = RSA_new(); > > prsa2 = d2i_RSAPrivateKey_fp(pFile, &prsa1); > > But there isn't really any point as you can just do: > > rsa = d2i_RSAPrivateKey_fp(pFile, NULL); > > Which will call RSA_new() internally. > I figured the same and took this approach too. Can you confirm the same logic applies to d2i_X509_fp? Nick ______________________________________________________________________ OpenSSL Project http://www.openssl.org User Support Mailing List openssl-users@openssl.org Automated List Manager majord...@openssl.org