<div dir="ltr"><div><div><div>X509_STORE_add_cert increments the reference count of the each cert, but only by 1.<br></div>X509_STORE_free decrements the ref count by 1. So after decrementing, if ref_count is 0, certificate will be freed. <br></div><br>Jakob is saying that if you want them to stay even after X509_STORE_free, explicitly increment the ref count before calling free using something like below.<br><br>CRYPTO_add(certificate->references, 1, CRYPTO_LOCK_X509);<br><br><br></div><div>decrypt the ref count when you really want to free them and call X509_free(certificate).<br><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On 10 June 2015 at 10:20, Nayna Jain <span dir="ltr"><<a href="mailto:naynjain@in.ibm.com" target="_blank">naynjain@in.ibm.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div bgcolor="#FFFFFF">
<p><font size="2" face="sans-serif">Thanks Jacob,</font><br>
<font size="2" face="sans-serif">So, does that API do not increment reference count internally itself.</font><br>
<br>
<font size="2" face="sans-serif">I mean if I have to explicitly do that, what is the API for that ? </font><br><span class="">
<br>
<font size="2" face="sans-serif">Thanks & Regards,<br>
Nayna Jain</font><br>
<br>
</span><img src="cid:1__=EABBF4F3DF89F6F38f9e8a93df938@in.ibm.com" alt="Inactive hide details for Jakob Bohm ---06/10/2015 09:49:54 AM---On 10/06/2015 05:22, Nayna Jain wrote: >" height="16" width="16" border="0"><font size="2" color="#424282" face="sans-serif">Jakob Bohm ---06/10/2015 09:49:54 AM---On 10/06/2015 05:22, Nayna Jain wrote: ></font><br>
<br>
<font size="1" color="#5F5F5F" face="sans-serif">From:      </font><font size="1" face="sans-serif">Jakob Bohm <<a href="mailto:jb-openssl@wisemo.com" target="_blank">jb-openssl@wisemo.com</a>></font><br>
<font size="1" color="#5F5F5F" face="sans-serif">To:        </font><font size="1" face="sans-serif"><a href="mailto:openssl-users@openssl.org" target="_blank">openssl-users@openssl.org</a></font><br>
<font size="1" color="#5F5F5F" face="sans-serif">Date:      </font><font size="1" face="sans-serif">06/10/2015 09:49 AM</font><br>
<font size="1" color="#5F5F5F" face="sans-serif">Subject:   </font><font size="1" face="sans-serif">Re: [openssl-users] X509_STORE_free() and X509_LOOKUP_free() also frees the X509 certificates inside it</font><br>
<font size="1" color="#5F5F5F" face="sans-serif">Sent by:   </font><font size="1" face="sans-serif">"openssl-users" <<a href="mailto:openssl-users-bounces@openssl.org" target="_blank">openssl-users-bounces@openssl.org</a>></font><br>
</p><hr style="color:#8091a5" noshade size="2" width="100%" align="left"><div><div class="h5"><br>
<br>
<br>
<br>
<font size="3" face="serif">On 10/06/2015 05:22, Nayna Jain wrote:</font>
<ul style="padding-left:36pt"><br>
<font size="2" face="sans-serif">Hi all,</font><font size="3" face="serif"><br>
</font><font size="2" face="sans-serif"><br>
I am using X509_STORE and X509_LOOKUP to verify the certificate and its chain.</font><font size="3" face="serif"><br>
</font><font size="2" face="sans-serif"><br>
But at the end when I do X509_STORE_free(store)  and X509_LOOKUP_free(lookup), it is also doing free of the X509* certificate which I added.<br>
But I don't want that, because after that when I immediately try to access X509* certificate for further operation, then it results in core dump</font><font size="3" face="serif"><br>
</font><font size="2" face="sans-serif"><br>
And if I don't do X509_STORE_free() then it will leave the memory leak.<br>
<br>
Let me know how to resolve this and if I misunderstood something.</font></ul>
<br>
<tt><font size="3">X509 objects (and many other objects in the API) are <br>
reference counted.<br>
<br>
Increment the reference count of each certificate as <br>
you add it to the X509_STORE, this should make the <br>
X509 object stay around after X509_STORE_free() frees <br>
it.<br>
<br>
However there is a shortage of documentation on the <br>
reference counting functions involved.<br>
</font></tt><br>
<tt><font size="3">Enjoy<br>
<br>
Jakob<br>
-- <br>
Jakob Bohm, CIO, Partner, WiseMo A/S.  </font></tt><a href="http://www.wisemo.com/" target="_blank"><tt><font size="3" color="#0000FF"><u>http://www.wisemo.com</u></font></tt></a></div></div><tt><font size="3"><div><div class="h5"><br>
Transformervej 29, 2860 Søborg, Denmark.  Direct +45 31 13 16 10<br>
This public discussion message is non-binding and may contain errors.<br></div></div>
WiseMo - Remote Service Management for PCs, Phones and Embedded </font></tt><tt><font size="2">_______________________________________________<br>
openssl-users mailing list<br>
To unsubscribe: </font></tt><tt><font size="2"><a href="https://mta.openssl.org/mailman/listinfo/openssl-users" target="_blank">https://mta.openssl.org/mailman/listinfo/openssl-users</a></font></tt><tt><font size="2"><br>
</font></tt><br>
<p></p></div>
<br>_______________________________________________<br>
openssl-users mailing list<br>
To unsubscribe: <a href="https://mta.openssl.org/mailman/listinfo/openssl-users" target="_blank">https://mta.openssl.org/mailman/listinfo/openssl-users</a><br>
<br></blockquote></div><br></div>