<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xml:base="http://www.newlc.com" xmlns:dc="http://purl.org/dc/elements/1.1/">
<channel>
 <title>NewLC - TRAP/LEAVE leaking S60 winscw - Comments</title>
 <link>http://www.newlc.com/en/topic-17019</link>
 <description>Comments for &quot;TRAP/LEAVE leaking S60 winscw&quot;</description>
 <language>en</language>
<item>
 <title>Re: TRAP/LEAVE leaking S60 winscw</title>
 <link>http://www.newlc.com/en/topic-17019#comment-49872</link>
 <description>&lt;p&gt;First:&lt;br /&gt;
Please note this thread is 2 years old, noone should use the old ecrt0.lib anylonger unless they really have to.&lt;br /&gt;
You should use OpenC instead which is a much better implementation of libc.&lt;/p&gt;

&lt;p&gt;ragav_an: &lt;br /&gt;
I&#039;m not mika, but I have comments...&lt;br /&gt;
At first look, your statement looks kindof-right, but there is a couple of small and subtle problems with it that in my opinion makes what you write strange, and in part totally wrong.&lt;br /&gt;
Its possible its just in your use of english, but I comment anyhow in case you have misunderstood something...&lt;/p&gt;

&lt;p&gt;&quot;If the exe is linking with STDLIB, the user should link his executable against &quot;ecrt0.lib&quot; or a &quot; CTrapCleanup&quot; pointer should be provided.&quot;&lt;/p&gt;

&lt;p&gt;1.  &quot;provide a CTrapCleanup pointer&quot; is a bit weird way to say it, what you need to do is creating a CTrapCleanup instance, its irrelevant how you manage this instance in your code, but keeping a pointer to it is ofcourse a nice way to be able to destroy it when your app closes (not strictly needed, but makes for clean and nice code)&lt;br /&gt;
2. Its not link against ecrt0.lib &quot;or&quot; create ctrapcleanup, you have to do _both_&lt;br /&gt;
3. again, this is an obsolete lib that shouldn&#039;t be used at all...&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;</description>
 <pubDate>Tue, 30 Dec 2008 10:16:24 +0100</pubDate>
 <dc:creator>alh</dc:creator>
 <guid isPermaLink="false">comment 49872 at http://www.newlc.com</guid>
</item>
<item>
 <title>Re: TRAP/LEAVE leaking S60 winscw</title>
 <link>http://www.newlc.com/en/topic-17019#comment-49865</link>
 <description>&lt;p&gt;Hi,&lt;/p&gt;

&lt;p&gt;If the exe is linking with STDLIB, the user should link his executable against &quot;ecrt0.lib&quot; or a &quot; CTrapCleanup&quot; pointer should be provided.&lt;br /&gt;
If the program is a UI application then the  &quot;CTrapCleanup&quot; pointer will be provided by the framework.&lt;/p&gt;

&lt;p&gt;Mika, any comments or corrections regarding this.&lt;/p&gt;</description>
 <pubDate>Mon, 29 Dec 2008 08:13:08 +0100</pubDate>
 <dc:creator>raghav_an</dc:creator>
 <guid isPermaLink="false">comment 49865 at http://www.newlc.com</guid>
</item>
<item>
 <title>Re: TRAP/LEAVE leaking S60 winscw</title>
 <link>http://www.newlc.com/en/topic-17019#comment-49786</link>
 <description>&lt;p&gt;Maybe it&#039;s the CleanupStack&#039;s problem..&lt;/p&gt;</description>
 <pubDate>Mon, 22 Dec 2008 02:23:09 +0100</pubDate>
 <dc:creator>siblex</dc:creator>
 <guid isPermaLink="false">comment 49786 at http://www.newlc.com</guid>
</item>
<item>
 <title>Re: TRAP/LEAVE leaking S60 winscw</title>
 <link>http://www.newlc.com/en/topic-17019#comment-36272</link>
 <description>&lt;div class=&quot;smf-content&quot;&gt;Actually, without CloseSTDLIB I get a CONE 36.&lt;br /&gt;So I need both ClostSTDLIB &amp;amp;&amp;amp; _DisposeAllThreadData &lt;br /&gt;for it to work correctly. &lt;br /&gt;Also with a dummy trap in the main app during construction.&lt;br /&gt;At least now I can continue to see my own leaks and nothing else,&lt;br /&gt;again - thanks Mika. &lt;img src=&quot;/en/sites/all/modules/smf_filter/smf_smileys/smiley.gif&quot; alt=&quot;Smiley&quot; border=&quot;0&quot; /&gt;&lt;/div&gt;</description>
 <pubDate>Tue, 12 Dec 2006 10:40:08 +0100</pubDate>
 <dc:creator>iothal</dc:creator>
 <guid isPermaLink="false">comment 36272 at http://www.newlc.com</guid>
</item>
<item>
 <title>Re: TRAP/LEAVE leaking S60 winscw</title>
 <link>http://www.newlc.com/en/topic-17019#comment-36271</link>
 <description>&lt;div class=&quot;smf-content&quot;&gt;alh: thanks for jumping in. I&amp;#039;ve now dug deeper into it, and it seems that the problem only (or at least mainly) occurs if you are linking with ESTLIB.LIB.&lt;br /&gt;&lt;br /&gt;So _DisposeAllThreadData is the new CloseSTDLIB...?&lt;br /&gt;&lt;br /&gt;iothal: the thread allocation functions are defined in the CodeWarrior runtime code, to be found in Symbian_Support\MSL\MSL_C\MSL_Win32\Src\ in the CodeWarrior directory.&lt;br /&gt;&lt;br /&gt;I still assume there is a &amp;#039;correct&amp;#039; way of doing this somewhere.&lt;/div&gt;</description>
 <pubDate>Mon, 11 Dec 2006 20:41:58 +0100</pubDate>
 <dc:creator>mikaraento</dc:creator>
 <guid isPermaLink="false">comment 36271 at http://www.newlc.com</guid>
</item>
<item>
 <title>Re: TRAP/LEAVE leaking S60 winscw</title>
 <link>http://www.newlc.com/en/topic-17019#comment-36270</link>
 <description>&lt;div class=&quot;smf-content&quot;&gt;I wonder why I have never run into this.&lt;br /&gt;&lt;br /&gt;I have developed servers for 9.1 and 9.2, useing CodeWarrior, and my entry function typically looks like this:&lt;br /&gt;&lt;br /&gt;&lt;div class=&quot;codeheader&quot;&gt;Code:&lt;/div&gt;&lt;div class=&quot;code&quot;&gt;TInt ServerStartup::RunServer(TAny* aParam)&lt;br /&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;{&lt;br /&gt;&amp;nbsp; &amp;nbsp; __UHEAP_MARK;&lt;br /&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;CTrapCleanup* cleanup = CTrapCleanup::New();&lt;br /&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;TInt ret = KErrNoMemory;&lt;br /&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;if&lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;(cleanup)&lt;br /&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;{&lt;br /&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;TRAP(ret, ServerStartup::RunServerL());&lt;br /&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;delete cleanup;&lt;br /&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;}&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; __UHEAP_MARKEND;&lt;br /&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;return ret;&lt;br /&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;}&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;I have never got any false memory leaks with this code...&lt;br /&gt;&lt;br /&gt;I would like to know a bit more about when this occours for you...&lt;br /&gt;Is it only in emulator build? only on target build? both?&lt;br /&gt;&lt;br /&gt;Is it only if you use User::__DbgMarkCheck, but as above when you use only MarkEnd you don&amp;#039;t get the problem? (MarkEnd also gives the alloc fail panic)&lt;br /&gt;&lt;br /&gt;I use RVCT for target builds and build that from command line..&amp;nbsp; Only build to emulator from within codewarrior.&lt;br /&gt;&lt;br /&gt;But I&amp;#039;ve never seen this problem, even in emulator build, but it worries me some... would like to understand it before I run into it a week before some major release &lt;img src=&quot;/en/sites/all/modules/smf_filter/smf_smileys/smiley.gif&quot; alt=&quot;Smiley&quot; border=&quot;0&quot; /&gt;&lt;br /&gt;&lt;br /&gt;Could you explain it a bit further mika?&lt;/div&gt;</description>
 <pubDate>Mon, 11 Dec 2006 16:32:49 +0100</pubDate>
 <dc:creator>alh</dc:creator>
 <guid isPermaLink="false">comment 36270 at http://www.newlc.com</guid>
</item>
<item>
 <title>Re: TRAP/LEAVE leaking S60 winscw</title>
 <link>http://www.newlc.com/en/topic-17019#comment-36269</link>
 <description>&lt;div class=&quot;smf-content&quot;&gt;Thanks again Mika, it works like a charm now! &lt;img src=&quot;/en/sites/all/modules/smf_filter/smf_smileys/smiley.gif&quot; alt=&quot;Smiley&quot; border=&quot;0&quot; /&gt;&lt;br /&gt;Where did you find _DisposeAllThreadData btw, just curious... &lt;img src=&quot;/en/sites/all/modules/smf_filter/smf_smileys/wink.gif&quot; alt=&quot;Wink&quot; border=&quot;0&quot; /&gt;&lt;/div&gt;</description>
 <pubDate>Mon, 11 Dec 2006 15:19:58 +0100</pubDate>
 <dc:creator>iothal</dc:creator>
 <guid isPermaLink="false">comment 36269 at http://www.newlc.com</guid>
</item>
<item>
 <title>Re: TRAP/LEAVE leaking S60 winscw</title>
 <link>http://www.newlc.com/en/topic-17019#comment-36268</link>
 <description>&lt;div class=&quot;smf-content&quot;&gt;I have the feeling this is not the way it&amp;#039;s supposed to be done, but anyway, here&amp;#039;s a fix. Add a declaration&lt;br /&gt;&lt;br /&gt;&lt;div class=&quot;codeheader&quot;&gt;Code:&lt;/div&gt;&lt;div class=&quot;code&quot;&gt;#if defined(__WINS__) &amp;amp;&amp;amp; defined(EKA2)&lt;br /&gt;extern &amp;quot;C&amp;quot; {&lt;br /&gt;void _DisposeAllThreadData();&lt;br /&gt;}&lt;br /&gt;#endif&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;and a call to a suitable location, like:&lt;br /&gt;&lt;div class=&quot;codeheader&quot;&gt;Code:&lt;/div&gt;&lt;div class=&quot;code&quot;&gt;CSymbianOSUnitApplication::~CSymbianOSUnitApplication()&lt;br /&gt;{&lt;br /&gt;#if defined(__WINS__) &amp;amp;&amp;amp; defined(EKA2)&lt;br /&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;_DisposeAllThreadData();&lt;br /&gt;#endif&lt;br /&gt;}&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;Dlls that do not already have a clear tear-down function, the situation is more problematic.&lt;/div&gt;</description>
 <pubDate>Mon, 11 Dec 2006 11:27:49 +0100</pubDate>
 <dc:creator>mikaraento</dc:creator>
 <guid isPermaLink="false">comment 36268 at http://www.newlc.com</guid>
</item>
<item>
 <title>Re: TRAP/LEAVE leaking S60 winscw</title>
 <link>http://www.newlc.com/en/topic-17019#comment-36267</link>
 <description>&lt;div class=&quot;smf-content&quot;&gt;Thank you very much Mika!&lt;br /&gt;And yes, these things should be documented for sure! &lt;img src=&quot;/en/sites/all/modules/smf_filter/smf_smileys/smiley.gif&quot; alt=&quot;Smiley&quot; border=&quot;0&quot; /&gt;&lt;/div&gt;</description>
 <pubDate>Sun, 10 Dec 2006 15:09:28 +0100</pubDate>
 <dc:creator>iothal</dc:creator>
 <guid isPermaLink="false">comment 36267 at http://www.newlc.com</guid>
</item>
<item>
 <title>Re: TRAP/LEAVE leaking S60 winscw</title>
 <link>http://www.newlc.com/en/topic-17019#comment-36266</link>
 <description>&lt;div class=&quot;smf-content&quot;&gt;You are correct, TRAP/Leave does leak on Codewarrior with Symbian OS 9.1.&lt;br /&gt;&lt;br /&gt;On 9.1 TRAP/Leave are implemented with try/catch/throw. The Codewarrior implementation of c++ exceptions needs to allocate some support structures in thread local storage. These are allocated on the first use of TRAP/Leave.&lt;br /&gt;&lt;br /&gt;The only solution is to have a dummy TRAP(err, User::Leave(1)); outside the leak tracking.&lt;br /&gt;&lt;br /&gt;The stupid thing is that it seems that the support structures are at least sometimes allocated per module. So you actually need to have such a dummy TRAP exported from all the dlls you create, and call them before leak tracking.&lt;br /&gt;&lt;br /&gt;This does not seem to be a problem for platform modules. I don&amp;#039;t know why. Guesses:&lt;br /&gt;&lt;ul style=&quot;margin-top: 0; margin-bottom: 0;&quot;&gt;&lt;li&gt;The platform dlls are not using try/catch/throw&lt;/li&gt;&lt;li&gt;They force allocation of the thread local structures on load&lt;/li&gt;&lt;li&gt;They are compiled with a different set of runtime libraries or a modified compiler&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;Neither do you run across it with apps, where the framework does the tracking.&lt;br /&gt;&lt;br /&gt;Don&amp;#039;t you wish they&amp;#039;d document these things?&lt;/div&gt;</description>
 <pubDate>Sat, 09 Dec 2006 14:57:37 +0100</pubDate>
 <dc:creator>mikaraento</dc:creator>
 <guid isPermaLink="false">comment 36266 at http://www.newlc.com</guid>
</item>
<item>
 <title>Re: TRAP/LEAVE leaking S60 winscw</title>
 <link>http://www.newlc.com/en/topic-17019#comment-36265</link>
 <description>&lt;div class=&quot;smf-content&quot;&gt;Its interesting that this code runs as there isn&amp;#039;t a trap cleanup object created.&lt;br /&gt;&lt;br /&gt;Try this and see if you still have a leak:&lt;br /&gt;&lt;br /&gt;void PushLotsL()&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;TInt* dummy = NULL;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;for (TInt i = 0; i &amp;lt; 100; i++)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;CleanupStack::PushL(dummy);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;CleanupStack::Pop(100);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br /&gt;&lt;br /&gt;TInt E32Main()&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;static CTrapCleanup* TrapCleanup = CTrapCleanup::New();&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; PushLotsL();&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;remainder of your code&lt;br /&gt;&lt;br /&gt;P.S.&lt;br /&gt;Why are you calling the User functions directly and not using __UHEAP_MARK etc.?&lt;/div&gt;</description>
 <pubDate>Fri, 08 Dec 2006 20:53:37 +0100</pubDate>
 <dc:creator>NumptyAlert</dc:creator>
 <guid isPermaLink="false">comment 36265 at http://www.newlc.com</guid>
</item>
<item>
 <title>Re: TRAP/LEAVE leaking S60 winscw</title>
 <link>http://www.newlc.com/en/topic-17019#comment-36264</link>
 <description>&lt;div class=&quot;smf-content&quot;&gt;Sorry for that.&lt;br /&gt;&lt;br /&gt;According to me Yes, you are right. It should never fail. Its very strange that it says a memory leak.&lt;br /&gt;&lt;br /&gt;Cheers,&lt;br /&gt;Sri&lt;/div&gt;</description>
 <pubDate>Fri, 08 Dec 2006 11:49:46 +0100</pubDate>
 <dc:creator>srikanth</dc:creator>
 <guid isPermaLink="false">comment 36264 at http://www.newlc.com</guid>
</item>
<item>
 <title>Re: TRAP/LEAVE leaking S60 winscw</title>
 <link>http://www.newlc.com/en/topic-17019#comment-36263</link>
 <description>&lt;div class=&quot;smf-content&quot;&gt;Look at the code, it doesn&amp;#039;t allocate anything.&lt;br /&gt;It calls User::Leave and nothing else.&lt;br /&gt;&lt;br /&gt;cheers m8&lt;/div&gt;</description>
 <pubDate>Fri, 08 Dec 2006 11:41:08 +0100</pubDate>
 <dc:creator>iothal</dc:creator>
 <guid isPermaLink="false">comment 36263 at http://www.newlc.com</guid>
</item>
<item>
 <title>Re: TRAP/LEAVE leaking S60 winscw</title>
 <link>http://www.newlc.com/en/topic-17019#comment-36262</link>
 <description>&lt;div class=&quot;smf-content&quot;&gt;Wrong.&lt;br /&gt;&lt;br /&gt;Memory leaks can still there even if you use TRAP untill and unless you dont push the dynamic objects in to cleanup stack. This is especially required if you are calling any leaving functions after allocating memory for any dynamic objects.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Cheers,&lt;br /&gt;Sri&lt;/div&gt;</description>
 <pubDate>Fri, 08 Dec 2006 11:39:26 +0100</pubDate>
 <dc:creator>srikanth</dc:creator>
 <guid isPermaLink="false">comment 36262 at http://www.newlc.com</guid>
</item>
<item>
 <title>TRAP/LEAVE leaking S60 winscw</title>
 <link>http://www.newlc.com/en/topic-17019</link>
 <description>&lt;div class=&quot;smf-content&quot;&gt;&lt;/div&gt;&lt;p&gt;&lt;a href=&quot;http://www.newlc.com/en/topic-17019&quot;&gt;read more&lt;/a&gt;&lt;/p&gt;</description>
 <comments>http://www.newlc.com/en/topic-17019#comments</comments>
 <category domain="http://www.newlc.com/en/forums/symbian-c">Symbian C++</category>
 <pubDate>Fri, 08 Dec 2006 11:21:32 +0100</pubDate>
 <dc:creator>iothal</dc:creator>
 <guid isPermaLink="false">16585 at http://www.newlc.com</guid>
</item>
</channel>
</rss>
