<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title><![CDATA[wolfSSL - Embedded SSL Library — Cleanup bugs in wolfSSL_Init()]]></title>
		<link>https://www.wolfssl.com/forums/topic1560-cleanup-bugs-in-wolfsslinit.html</link>
		<atom:link href="https://www.wolfssl.com/forums/feed-rss-topic1560.xml" rel="self" type="application/rss+xml" />
		<description><![CDATA[The most recent posts in Cleanup bugs in wolfSSL_Init().]]></description>
		<lastBuildDate>Mon, 22 Jun 2020 20:16:06 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Re: Cleanup bugs in wolfSSL_Init()]]></title>
			<link>https://www.wolfssl.com/forums/post5288.html#p5288</link>
			<description><![CDATA[<p>Thanks,</p><p>I suppose it is debatable how serious failure to cleanup is when there is a fatal error to initialize wolfssl: it that case it is likely that the program will be terminated anyway.</p><p>The reason I fell over this however is because I&#039;m integrating wolfssl with my C++ library and found myself calling wolfSSL_init() from the constructor of a class:</p><div class="codebox"><pre><code>TLS::TLS() : m_session(nullptr)
{
  DoutEntering(dc::tls, &quot;TLS::TLS() [&quot; &lt;&lt; this &lt;&lt; &quot;]&quot;);
  std::call_once(s_flag, global_tls_initialization);
}</code></pre></div><p>where</p><div class="codebox"><pre><code>//static
void TLS::global_tls_initialization()
{
  DoutEntering(dc::tls|dc::notice, &quot;evio::protocol::TLS::global_tls_initialization()&quot;);

  // Call this to have wolfssl print debug output (wolfssl must be configured with --enable-debug).
  //wolfSSL_Debugging_ON();
  
  Dout(dc::tls|continued_cf, &quot;wolfSSL_Init() = &quot;);
  wolfssl_error_code ret = wolfSSL_Init();
  Dout(dc::finish, ret);
  if (ret != WOLFSSL_SUCCESS)
    THROW_FALERTC(ret, &quot;wolfSSL_Init&quot;);

...</code></pre></div><p>At that point, where I possibly throw an exception from a constructor, I feel strongly obliged to make SURE that there are no side effects from the constructor. A constructor that throws should have the effect like it wasn&#039;t called at all. This is just a holy rule that is etched into my coding habbits;</p><p>so, I naturally looked inside `wolfSSL_Init()` to make sure it had no side effects when it returned something other than WOLFSSL_SUCCESS.</p><p>In theory, it would be OK when wolfSSL_Init() had side effect (from the C coding point of view), but in that case it would be nice if it returned an error that allowed me to unwind all the damage. But that is certainly not possible, if only because it returns the same error codes from different stages of initialization.</p>]]></description>
			<author><![CDATA[null@example.com (carlo)]]></author>
			<pubDate>Mon, 22 Jun 2020 20:16:06 +0000</pubDate>
			<guid>https://www.wolfssl.com/forums/post5288.html#p5288</guid>
		</item>
		<item>
			<title><![CDATA[Re: Cleanup bugs in wolfSSL_Init()]]></title>
			<link>https://www.wolfssl.com/forums/post5287.html#p5287</link>
			<description><![CDATA[<p>We will look into it thank you so much for the report!</p><p>- KH</p>]]></description>
			<author><![CDATA[null@example.com (Kaleb J. Himes)]]></author>
			<pubDate>Mon, 22 Jun 2020 18:15:23 +0000</pubDate>
			<guid>https://www.wolfssl.com/forums/post5287.html#p5287</guid>
		</item>
		<item>
			<title><![CDATA[Cleanup bugs in wolfSSL_Init()]]></title>
			<link>https://www.wolfssl.com/forums/post5280.html#p5280</link>
			<description><![CDATA[<p>In wolfSSL_init(), if initRefCount == 0 when called and when wolfCrypt_Init() returns 0 (succeeds), then after that wolfCrypt_Cleanup() is <strong>not</strong> called if subsequently any additional error occurs.</p><p>Likewise, if the call to wolfSSL_RAND_seed succeeds, but an error happens after that then also wolfSSL_RAND_Cleanup() is <strong>not</strong> called to clean up.</p><p>Finally, if `wc_InitMutex(&amp;session_mutex)` succeeds, but an error happens after that then `wc_FreeMutex` is not called and<br />if `wc_InitMutex(&amp;count_mutex)` succeeds but `wc_LockMutex(&amp;count_mutex)` fails, then again `wc_FreeMutex` is not called.</p>]]></description>
			<author><![CDATA[null@example.com (carlo)]]></author>
			<pubDate>Sun, 21 Jun 2020 01:57:46 +0000</pubDate>
			<guid>https://www.wolfssl.com/forums/post5280.html#p5280</guid>
		</item>
	</channel>
</rss>
