<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[thisptr unter Linux in Destruktor ungültig?]]></title><description><![CDATA[<p>Hallo!</p>
<p>Folgendes Konstrukt:</p>
<pre><code class="language-cpp">CSystem::~CSystem()
{
	// this ist valid
	// this-&gt;m_pInformation ist valid und vom Typ CData*
	this-&gt;m_pInformation-&gt;DeleteSelf();
}

// ...

void CData::DeleteSelf()
{
	// geht nocht
	cout &lt;&lt; &quot;CData::DeleteSelf wird aufgerufen&quot; &lt;&lt; endl;

	// ACHTUNG: Thisptr ist 0?!?!?!
	cout &lt;&lt; &quot;Thisptr: &quot; &lt;&lt; this &lt;&lt; endl;

	// Crash (Segmention fault), da this ja 0 ist
	cout &lt;&lt; &quot;Root: &quot; &lt;&lt; this-&gt;m_bRoot &lt;&lt; endl;

	if (!this-&gt;m_bRoot)
	{
		// rekursives löschen
		this-&gt;m_pParent-&gt;DeleteSelf();
	}
	else
	{
		delete this;
	}
}
</code></pre>
<p>Problem: Es crasht, da der thisptr unverständlicherweise 0 ist. Unter Windows klappt das ganze, unter Linux (Debian Lenny, gcc 4.1.3) nicht. Auch wenn ich es noch so viel betrachte: Ich sehe keinen logischen Fehler?!</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/277129/thisptr-unter-linux-in-destruktor-ungültig</link><generator>RSS for Node</generator><lastBuildDate>Wed, 26 Aug 2026 01:43:39 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/277129.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 13 Nov 2010 13:47:47 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to thisptr unter Linux in Destruktor ungültig? on Sat, 13 Nov 2010 13:47:47 GMT]]></title><description><![CDATA[<p>Hallo!</p>
<p>Folgendes Konstrukt:</p>
<pre><code class="language-cpp">CSystem::~CSystem()
{
	// this ist valid
	// this-&gt;m_pInformation ist valid und vom Typ CData*
	this-&gt;m_pInformation-&gt;DeleteSelf();
}

// ...

void CData::DeleteSelf()
{
	// geht nocht
	cout &lt;&lt; &quot;CData::DeleteSelf wird aufgerufen&quot; &lt;&lt; endl;

	// ACHTUNG: Thisptr ist 0?!?!?!
	cout &lt;&lt; &quot;Thisptr: &quot; &lt;&lt; this &lt;&lt; endl;

	// Crash (Segmention fault), da this ja 0 ist
	cout &lt;&lt; &quot;Root: &quot; &lt;&lt; this-&gt;m_bRoot &lt;&lt; endl;

	if (!this-&gt;m_bRoot)
	{
		// rekursives löschen
		this-&gt;m_pParent-&gt;DeleteSelf();
	}
	else
	{
		delete this;
	}
}
</code></pre>
<p>Problem: Es crasht, da der thisptr unverständlicherweise 0 ist. Unter Windows klappt das ganze, unter Linux (Debian Lenny, gcc 4.1.3) nicht. Auch wenn ich es noch so viel betrachte: Ich sehe keinen logischen Fehler?!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1979891</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1979891</guid><dc:creator><![CDATA[Lord_Axiom]]></dc:creator><pubDate>Sat, 13 Nov 2010 13:47:47 GMT</pubDate></item><item><title><![CDATA[Reply to thisptr unter Linux in Destruktor ungültig? on Sat, 13 Nov 2010 14:58:32 GMT]]></title><description><![CDATA[<p>Wahrscheinlich schlechtes Design, vermeide einfach <code>delete this</code> , da es sehr heikel ist, gerade im Zusammenhang mit deinem Kommentar &quot;rekursives Loeschen&quot;. Hast du denn mal debugged und geschaut, wo es genau crashed?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1979924</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1979924</guid><dc:creator><![CDATA[knivil]]></dc:creator><pubDate>Sat, 13 Nov 2010 14:58:32 GMT</pubDate></item><item><title><![CDATA[Reply to thisptr unter Linux in Destruktor ungültig? on Sat, 13 Nov 2010 15:24:53 GMT]]></title><description><![CDATA[<p>Poste mal den gesamten Code.</p>
<p>Wenn du einen Compilerfehler vermutest: test mal mit einer GCC 3.x Version und mit neueren 4.x versionen (4.5.1).</p>
<p>Und wie knivil schon angedeutet hat: der Debugger ist dein Freund. Ich sehe keinen Grund warum wir raten sollen, statt dass du mal hergehst und GDB anwirfst.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1979939</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1979939</guid><dc:creator><![CDATA[hustbaer]]></dc:creator><pubDate>Sat, 13 Nov 2010 15:24:53 GMT</pubDate></item><item><title><![CDATA[Reply to thisptr unter Linux in Destruktor ungültig? on Sat, 13 Nov 2010 15:42:06 GMT]]></title><description><![CDATA[<p>Hi.<br />
Ich habe nun mal gdb verwendet (zum ersten mal), aber viel mehr sagen als das was ich schon wusste tut er ja auch nicht:</p>
<pre><code>Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0xf7c866c0 (LWP 26863)]
0x0804d76d in CData::DeleteSelf (this=0x0)
    at /home/test/CData.cpp:41
</code></pre>
<p>Zeile 41 entspricht Zeile 19 aus meinem ersten Post. Der Crash passiert natürlich genau da, da ich auf einen <code>this</code> -ptr zugreife, der den Wert 0 hat.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1979950</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1979950</guid><dc:creator><![CDATA[Lord_Axiom]]></dc:creator><pubDate>Sat, 13 Nov 2010 15:42:06 GMT</pubDate></item><item><title><![CDATA[Reply to thisptr unter Linux in Destruktor ungültig? on Sat, 13 Nov 2010 16:45:18 GMT]]></title><description><![CDATA[<p>EDIT:</p>
<p>Ups... War wohl falsch...</p>
<p>Lass dir</p>
<pre><code class="language-cpp">this-&gt;m_pParent
</code></pre>
<p>mal ausgeben...</p>
<p>Der wird vermutlich 0 sein</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1979981</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1979981</guid><dc:creator><![CDATA[XSpille]]></dc:creator><pubDate>Sat, 13 Nov 2010 16:45:18 GMT</pubDate></item><item><title><![CDATA[Reply to thisptr unter Linux in Destruktor ungültig? on Sat, 13 Nov 2010 17:00:45 GMT]]></title><description><![CDATA[<p>Mhh, drücke ich mich wirklich so schlecht aus?<br />
Auf <code>m_pParent</code> kann ich gar nicht erst zugreifen, da schon <code>this-&gt;</code> 0 ist. (siehe Zeile 15/16)</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1979992</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1979992</guid><dc:creator><![CDATA[Lord_Axiom]]></dc:creator><pubDate>Sat, 13 Nov 2010 17:00:45 GMT</pubDate></item><item><title><![CDATA[Reply to thisptr unter Linux in Destruktor ungültig? on Sat, 13 Nov 2010 17:05:43 GMT]]></title><description><![CDATA[<p>du löscht aber nicht zufällig von der wurzel zu den blättern <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f615.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--confused_face"
      title=":confused:"
      alt="😕"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1980000</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1980000</guid><dc:creator><![CDATA[__--]]></dc:creator><pubDate>Sat, 13 Nov 2010 17:05:43 GMT</pubDate></item><item><title><![CDATA[Reply to thisptr unter Linux in Destruktor ungültig? on Sat, 13 Nov 2010 17:24:28 GMT]]></title><description><![CDATA[<p>Lord_Axiom schrieb:</p>
<blockquote>
<p>Mhh, drücke ich mich wirklich so schlecht aus?<br />
Auf <code>m_pParent</code> kann ich gar nicht erst zugreifen, da schon <code>this-&gt;</code> 0 ist. (siehe Zeile 15/16)</p>
</blockquote>
<p>Ich rede nicht von deinem Objekt, wo es knallt, sondern von dem Objekt, das<br />
DeleteSelf(); aufruft. Dort wird m_pParent evtl. schon 0 sein.</p>
<p>Irgendwo in deinem Code rufst du wahrscheinlich DeleteSelf(); auf einem<br />
Pointer auf, der auf 0 verweist...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1980005</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1980005</guid><dc:creator><![CDATA[XSpille]]></dc:creator><pubDate>Sat, 13 Nov 2010 17:24:28 GMT</pubDate></item><item><title><![CDATA[Reply to thisptr unter Linux in Destruktor ungültig? on Sat, 13 Nov 2010 21:05:41 GMT]]></title><description><![CDATA[<p>Soweit wie ich die undurchsichtige Geschichte verstehe, baut er eine einfach verkettete Liste nach.</p>
<p>Falls du alles so lassen willst, wie es jetzt ist, hätte ich das Ganze am ehesten in den Destruktor verschoben:</p>
<pre><code class="language-cpp">// void CData::DeleteSelf() // heisst jetzt
CData::~CData
{
    if (!this-&gt;m_bRoot) {
        // rekursives löschen
        delete this-&gt;m_pParent;
    }
    // else warum // else??? Falls das einen Sinn hat, ist diese Variante falsch
    //{
    //    delete this; // wird automatisch ausgeführt
    //}
    ... // &lt;-- und zwar hier
}
</code></pre>
<p>Wenn ich dem noch meinen eigenen Stil aufzwinge, sieht das Ganze so aus:</p>
<pre><code class="language-cpp">class system_data {
  // Reine Daten, alle Pointer smart gemacht, wird automatisch weggeräumt
}

class system {
private:
  std::list&lt;system_data&gt; info; // wird automatisch weggeräumt
}
</code></pre>
<p>Du brauchst dann weder delete this noch sonst irgend einen Destruktor.<br />
Du musst das Übel an der Wurzel packen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1980111</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1980111</guid><dc:creator><![CDATA[übelanderwurzel]]></dc:creator><pubDate>Sat, 13 Nov 2010 21:05:41 GMT</pubDate></item><item><title><![CDATA[Reply to thisptr unter Linux in Destruktor ungültig? on Sun, 14 Nov 2010 00:26:12 GMT]]></title><description><![CDATA[<p>übelanderwurzel schrieb:</p>
<blockquote>
<p>Du musst das Übel an der Wurzel packen.</p>
</blockquote>
<p>Designtechnisch kann man über die Notwendigkeit von &quot;delete this&quot; sicherlich<br />
diskutieren.</p>
<p>In seinem Fall scheint mir sein &quot;delete this&quot; (, falls er nichts verheimlicht),<br />
aber als wenig kritisch:<br />
<a href="http://www.parashift.com/c++-faq-lite/freestore-mgmt.html#faq-16.15" rel="nofollow">http://www.parashift.com/c++-faq-lite/freestore-mgmt.html#faq-16.15</a></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1980153</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1980153</guid><dc:creator><![CDATA[XSpille]]></dc:creator><pubDate>Sun, 14 Nov 2010 00:26:12 GMT</pubDate></item><item><title><![CDATA[Reply to thisptr unter Linux in Destruktor ungültig? on Sat, 13 Nov 2010 23:41:24 GMT]]></title><description><![CDATA[<p>Lord_Axiom schrieb:</p>
<blockquote>
<p>Ich habe nun mal gdb verwendet (zum ersten mal), aber viel mehr sagen als das was ich schon wusste tut er ja auch nicht:<br />
(...)</p>
</blockquote>
<p>Schnapp die eine IDE und Step Zeile für Zeile durch, und guck was passiert (wo genau etwas NULL wird was nicht NULL sein sollte).</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1980158</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1980158</guid><dc:creator><![CDATA[hustbaer]]></dc:creator><pubDate>Sat, 13 Nov 2010 23:41:24 GMT</pubDate></item></channel></rss>