<?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[DAMAGE: after normal block(xx) at (0xyy)]]></title><description><![CDATA[<p>Hallo,</p>
<p>ich habe ein Programm das die Fehlermeldung DAMAGE: after normal block(xx) at (0xyy) ausgibt.<br />
Beim Debuggen sieht es dann folgendermaßen aus:</p>
<p>_free_dbg_lk(void*,int)<br />
_free_dbg_lk(pUserData, nBlockUse)<br />
operator delete(void*)<br />
GiST::WriteNode(GiSTnode*)</p>
<p>wobei die Methode WriteNode so implementiert ist:</p>
<pre><code class="language-cpp">void 
GiST::WriteNode(GiSTnode *node)
{
	cout &lt;&lt; &quot;gist.cpp writenode-methode\n&quot; &lt;&lt; endl;
	cout &lt;&lt; &quot;buffer size &quot; &lt;&lt; store-&gt;PageSize() &lt;&lt; &quot;\n&quot; &lt;&lt; endl;
	char *buf=new char[store-&gt;PageSize()];

	// make Purify happy
	memset(buf, 0, store-&gt;PageSize());

#ifdef PRINTING_OBJECTS
	if(debug) {
		cout &lt;&lt; &quot;WRITE PAGE &quot; &lt;&lt; node-&gt;Path().Page() &lt;&lt; &quot;:\n&quot;;
		node-&gt;Print(cout);
	}
#endif
	node-&gt;Pack(buf);
	store-&gt;Write(node-&gt;Path().Page(), buf);
	delete buf;
}
</code></pre>
<p>Beim Befehl delete buf bleibt er mit dem fehler hängen. Allerdings nicht immer, sondern nur wenn der Aufruf von writenode durch diese methode passiert (die ruft writenode zweimal auf - einmal funktioniert beim anderen nicht):</p>
<pre><code class="language-cpp">void 
GiST::Split(GiSTnode **node, const GiSTentry&amp; entry)
{
	int went_left=0, new_root=0;

	if((*node)-&gt;Path().IsRoot()) {
		new_root=1;
		(*node)-&gt;Path().MakeChild(store-&gt;Allocate());
	}

	GiSTnode *node2=(*node)-&gt;PickSplit();
	node2-&gt;Path().MakeSibling(store-&gt;Allocate());
	GiSTentry *e=(*node)-&gt;SearchPtr(entry.Ptr());

	if(e!=NULL) {
		went_left=1;
		delete e;
	}
	node2-&gt;SetSibling((*node)-&gt;Sibling());
	(*node)-&gt;SetSibling(node2-&gt;Path().Page());
	WriteNode(*node);   //dieses writeNode wird noch korrekt ausgeführt
	WriteNode(node2);   //dieses nicht mehr

	GiSTentry *e1=(*node)-&gt;Union();
	GiSTentry *e2=node2-&gt;Union();

	e1-&gt;SetPtr((*node)-&gt;Path().Page());
	e2-&gt;SetPtr(node2-&gt;Path().Page());
	// Create new root if root is being split
	if (new_root) {
		GiSTnode *root=NewNode(this);

		root-&gt;SetLevel((*node)-&gt;Level()+1);
		root-&gt;InsertBefore(*e1, 0);
		root-&gt;InsertBefore(*e2, 1);
		root-&gt;Path().MakeRoot();
		WriteNode(root);
		delete root;
	}
	else {
		// Insert entry for N' in parent
		GiSTpath parent_path=(*node)-&gt;Path();
		parent_path.MakeParent();
		GiSTnode *parent=ReadNode(parent_path);
		// Find the entry for N in parent
		GiSTentry *e=parent-&gt;SearchPtr((*node)-&gt;Path().Page());
		assert(e!=NULL);
		// Insert the new entry right after it
		int pos=e-&gt;Position();

		parent-&gt;DeleteEntry(pos);
		parent-&gt;InsertBefore(*e1, pos);
		parent-&gt;InsertBefore(*e2, pos+1);
		delete e;
		if(!parent-&gt;IsOverFull(*store)) WriteNode(parent);
		else {
			Split(&amp;parent, went_left? *e1: *e2);
			GiSTpage page=(*node)-&gt;Path().Page();

			(*node)-&gt;Path()=parent-&gt;Path();
			(*node)-&gt;Path().MakeChild(page);
			page=node2-&gt;Path().Page();
			node2-&gt;Path()=(*node)-&gt;Path();
			node2-&gt;Path().MakeSibling(page);
		}
		delete parent;
	}
	if(!went_left) {
		delete *node;
		*node=node2;
	}
	else delete node2;
	delete e1;
	delete e2;
}
</code></pre>
<p>Ich habe echt keine Ahnung mehr woran das liegt. Habe diverses in Google gefunden, aber geholfen hat nichts. Irgendwas mit dem local Heap geht wohl nicht.</p>
<p>Gruß Simpson84</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/266288/damage-after-normal-block-xx-at-0xyy</link><generator>RSS for Node</generator><lastBuildDate>Thu, 03 Sep 2026 08:19:22 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/266288.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 06 May 2010 17:35:43 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to DAMAGE: after normal block(xx) at (0xyy) on Thu, 06 May 2010 17:35:43 GMT]]></title><description><![CDATA[<p>Hallo,</p>
<p>ich habe ein Programm das die Fehlermeldung DAMAGE: after normal block(xx) at (0xyy) ausgibt.<br />
Beim Debuggen sieht es dann folgendermaßen aus:</p>
<p>_free_dbg_lk(void*,int)<br />
_free_dbg_lk(pUserData, nBlockUse)<br />
operator delete(void*)<br />
GiST::WriteNode(GiSTnode*)</p>
<p>wobei die Methode WriteNode so implementiert ist:</p>
<pre><code class="language-cpp">void 
GiST::WriteNode(GiSTnode *node)
{
	cout &lt;&lt; &quot;gist.cpp writenode-methode\n&quot; &lt;&lt; endl;
	cout &lt;&lt; &quot;buffer size &quot; &lt;&lt; store-&gt;PageSize() &lt;&lt; &quot;\n&quot; &lt;&lt; endl;
	char *buf=new char[store-&gt;PageSize()];

	// make Purify happy
	memset(buf, 0, store-&gt;PageSize());

#ifdef PRINTING_OBJECTS
	if(debug) {
		cout &lt;&lt; &quot;WRITE PAGE &quot; &lt;&lt; node-&gt;Path().Page() &lt;&lt; &quot;:\n&quot;;
		node-&gt;Print(cout);
	}
#endif
	node-&gt;Pack(buf);
	store-&gt;Write(node-&gt;Path().Page(), buf);
	delete buf;
}
</code></pre>
<p>Beim Befehl delete buf bleibt er mit dem fehler hängen. Allerdings nicht immer, sondern nur wenn der Aufruf von writenode durch diese methode passiert (die ruft writenode zweimal auf - einmal funktioniert beim anderen nicht):</p>
<pre><code class="language-cpp">void 
GiST::Split(GiSTnode **node, const GiSTentry&amp; entry)
{
	int went_left=0, new_root=0;

	if((*node)-&gt;Path().IsRoot()) {
		new_root=1;
		(*node)-&gt;Path().MakeChild(store-&gt;Allocate());
	}

	GiSTnode *node2=(*node)-&gt;PickSplit();
	node2-&gt;Path().MakeSibling(store-&gt;Allocate());
	GiSTentry *e=(*node)-&gt;SearchPtr(entry.Ptr());

	if(e!=NULL) {
		went_left=1;
		delete e;
	}
	node2-&gt;SetSibling((*node)-&gt;Sibling());
	(*node)-&gt;SetSibling(node2-&gt;Path().Page());
	WriteNode(*node);   //dieses writeNode wird noch korrekt ausgeführt
	WriteNode(node2);   //dieses nicht mehr

	GiSTentry *e1=(*node)-&gt;Union();
	GiSTentry *e2=node2-&gt;Union();

	e1-&gt;SetPtr((*node)-&gt;Path().Page());
	e2-&gt;SetPtr(node2-&gt;Path().Page());
	// Create new root if root is being split
	if (new_root) {
		GiSTnode *root=NewNode(this);

		root-&gt;SetLevel((*node)-&gt;Level()+1);
		root-&gt;InsertBefore(*e1, 0);
		root-&gt;InsertBefore(*e2, 1);
		root-&gt;Path().MakeRoot();
		WriteNode(root);
		delete root;
	}
	else {
		// Insert entry for N' in parent
		GiSTpath parent_path=(*node)-&gt;Path();
		parent_path.MakeParent();
		GiSTnode *parent=ReadNode(parent_path);
		// Find the entry for N in parent
		GiSTentry *e=parent-&gt;SearchPtr((*node)-&gt;Path().Page());
		assert(e!=NULL);
		// Insert the new entry right after it
		int pos=e-&gt;Position();

		parent-&gt;DeleteEntry(pos);
		parent-&gt;InsertBefore(*e1, pos);
		parent-&gt;InsertBefore(*e2, pos+1);
		delete e;
		if(!parent-&gt;IsOverFull(*store)) WriteNode(parent);
		else {
			Split(&amp;parent, went_left? *e1: *e2);
			GiSTpage page=(*node)-&gt;Path().Page();

			(*node)-&gt;Path()=parent-&gt;Path();
			(*node)-&gt;Path().MakeChild(page);
			page=node2-&gt;Path().Page();
			node2-&gt;Path()=(*node)-&gt;Path();
			node2-&gt;Path().MakeSibling(page);
		}
		delete parent;
	}
	if(!went_left) {
		delete *node;
		*node=node2;
	}
	else delete node2;
	delete e1;
	delete e2;
}
</code></pre>
<p>Ich habe echt keine Ahnung mehr woran das liegt. Habe diverses in Google gefunden, aber geholfen hat nichts. Irgendwas mit dem local Heap geht wohl nicht.</p>
<p>Gruß Simpson84</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1893438</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1893438</guid><dc:creator><![CDATA[Simpson84]]></dc:creator><pubDate>Thu, 06 May 2010 17:35:43 GMT</pubDate></item><item><title><![CDATA[Reply to DAMAGE: after normal block(xx) at (0xyy) on Thu, 06 May 2010 17:44:30 GMT]]></title><description><![CDATA[<p>Boar... Also nicht nur, dass die Fkt. viel zu lang ist, ich seh auch nicht durch, wo dort ein Objekt wem gehört - also wer es zerstören darf/muss/sollte und wer eben nicht... (und dort wird der fehler auch liegen)</p>
<p>allein schon das ständige (*node)-&gt; ist sehr eklig anzusehen <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f61b.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--face_with_tongue"
      title=":P"
      alt="😛"
    /></p>
<p>Splitte die Fkt doch mal in paar Unterfkt. auf, dann sieht man da vll auch noch durch...</p>
<p>bb</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1893440</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1893440</guid><dc:creator><![CDATA[unskilled]]></dc:creator><pubDate>Thu, 06 May 2010 17:44:30 GMT</pubDate></item><item><title><![CDATA[Reply to DAMAGE: after normal block(xx) at (0xyy) on Thu, 06 May 2010 17:48:04 GMT]]></title><description><![CDATA[<p>Du schreibst irgendwo in Speicher, der dir nicht gehört. Dass passiert meistens wenn man irgendwas mit new[] gefrickelt hat statt Container zu benutzen, und mehr in den Speicherbereich reingeschrieben hat als reinpasst. Beim delete merkt die Runtime das und bringt diese &quot;damage after normal block&quot;-Fehler.<br />
Die genaue Stelle ist oft nicht offensichtlich. Die Kristallkugel sagt, dass du dir</p>
<pre><code class="language-cpp">store-&gt;Write(node-&gt;Path().Page(), buf);
</code></pre>
<p>mal genauer anschauen sollst.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1893441</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1893441</guid><dc:creator><![CDATA[Nukularfüsiker]]></dc:creator><pubDate>Thu, 06 May 2010 17:48:04 GMT</pubDate></item><item><title><![CDATA[Reply to DAMAGE: after normal block(xx) at (0xyy) on Thu, 06 May 2010 18:15:45 GMT]]></title><description><![CDATA[<p>Meine Verteidigung zu der sehr langen Funktion ist, dass ich den Code nicht selber geschrieben habe, sondern einfach nur verwenden möchte. Ich habe auch nicht besonders viel C++ Erfahrung, da ich bis jetzt immer alles in Java implementiert habe. Dort muss man sich ja auch nicht mit der Speicherfreigabe beschäftigen.<br />
Der Aufruf store-&gt;Write(node-&gt;Path().Page(), buf) führt hier hin.</p>
<pre><code class="language-cpp">void 
MTfile::Write(GiSTpage page, const char *buf)
{
	if(IsOpen()) {
		lseek(fileHandle, page*PageSize(), SEEK_SET);
		write(fileHandle, buf, PageSize());
		IOwrite++;
	}
}
</code></pre>
<p>Wenn ich die write-Methode hier richtig interpretiere, dann wird in fileHandle der Inhalt von buf hineingeschrieben, oder? Dann kann hier buf nicht übergelaufen sein. Auch der zweite Aufruf node-&gt;Pack(buf), in dem der buf eine Rolle spielt macht für mich den Eindruck, als würde buf dabei nicht verändert.</p>
<pre><code class="language-cpp">void 
GiSTnode::Pack(char *page) const
{
	// Pack the header
	GiSTheader *h=(GiSTheader *) page;

	h-&gt;level=Level();
	h-&gt;numEntries=NumEntries();
	h-&gt;sibling=Sibling();

	int fixlen=FixedLength();
	GiSTlte *ltable=(GiSTlte *)(page+tree-&gt;Store()-&gt;PageSize());
	GiSTlte ltptr=GIST_PAGE_HEADER_SIZE;

	for(int i=0; i&lt;numEntries; i++) {
		GiSTcompressedEntry compressedEntry=(*this)[i]-&gt;Compress();

		if(fixlen) assert(fixlen==compressedEntry.keyLen);
		// Copy the entry onto the page
		if(compressedEntry.keyLen&gt;0) memcpy(page+ltptr, compressedEntry.key, compressedEntry.keyLen);
		memcpy(page+ltptr+compressedEntry.keyLen, &amp;compressedEntry.ptr, sizeof(GiSTpage));
		// Be tidy
		if(compressedEntry.key) delete compressedEntry.key;
		// Enter a pointer to the entry in the line table
		if(!fixlen) *--ltable=ltptr;
		ltptr+=compressedEntry.keyLen+sizeof(GiSTpage);
	}
	// Store extra line table entry so we know last entry's length
	*--ltable=ltptr;
}
</code></pre>
<p>Für mich sieht das also so aus, als wird buf in GiST::WriteNode erstellt, dann passiert nicht mehr viel mit ihm und dann wird er dort wieder gelöscht.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1893457</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1893457</guid><dc:creator><![CDATA[Simpson84]]></dc:creator><pubDate>Thu, 06 May 2010 18:15:45 GMT</pubDate></item><item><title><![CDATA[Reply to DAMAGE: after normal block(xx) at (0xyy) on Thu, 06 May 2010 18:33:56 GMT]]></title><description><![CDATA[<p>Simpson84 schrieb:</p>
<blockquote>
<p>Meine Verteidigung zu der sehr langen Funktion ist, dass ich den Code nicht selber geschrieben habe, sondern einfach nur verwenden möchte.</p>
</blockquote>
<p>Das ist keine Entschuldigung <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /> Man sollte keinen Code verwenden, den man nicht versteht.<br />
Wenn man ihn aber versteht, gibts keine Entschuldigung, ihn nicht etwas übersichtlicher zu machen (d.h. in kleinere Funktionen zu zerlegen) <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1893467</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1893467</guid><dc:creator><![CDATA[pumuckl]]></dc:creator><pubDate>Thu, 06 May 2010 18:33:56 GMT</pubDate></item><item><title><![CDATA[Reply to DAMAGE: after normal block(xx) at (0xyy) on Fri, 07 May 2010 10:43:30 GMT]]></title><description><![CDATA[<p>Ich habe in den Sourcecode mal mehrere assert(_CrtCheckMemory()); eingefügt und dabei crashed das ganze in der Pack-Methode direkt nach</p>
<pre><code class="language-cpp">// Copy the entry onto the page
if(compressedEntry.keyLen&gt;0) memcpy(page+ltptr, compressedEntry.key, compressedEntry.keyLen);
</code></pre>
<p>Sieht jemand die Ursache dafür?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1893727</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1893727</guid><dc:creator><![CDATA[Simpson84]]></dc:creator><pubDate>Fri, 07 May 2010 10:43:30 GMT</pubDate></item><item><title><![CDATA[Reply to DAMAGE: after normal block(xx) at (0xyy) on Fri, 07 May 2010 11:02:15 GMT]]></title><description><![CDATA[<p>Ein Debugger könnte dir sicher besser weiterhelfen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1893733</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1893733</guid><dc:creator><![CDATA[Nukularfüsiker]]></dc:creator><pubDate>Fri, 07 May 2010 11:02:15 GMT</pubDate></item><item><title><![CDATA[Reply to DAMAGE: after normal block(xx) at (0xyy) on Fri, 07 May 2010 12:31:21 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">char *buf=new char[store-&gt;PageSize()]; 

    //...

    delete[] buf; // &lt;-- statt delete buf;
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1893764</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1893764</guid><dc:creator><![CDATA[seldon]]></dc:creator><pubDate>Fri, 07 May 2010 12:31:21 GMT</pubDate></item><item><title><![CDATA[Reply to DAMAGE: after normal block(xx) at (0xyy) on Fri, 07 May 2010 12:52:18 GMT]]></title><description><![CDATA[<p>So ein einfacher Fehler und keiner sieht ihn ^^</p>
<p>Ich hab ihn auch nicht gesehen.</p>
<p>gw,<br />
seldon</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1893773</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1893773</guid><dc:creator><![CDATA[_)))]]></dc:creator><pubDate>Fri, 07 May 2010 12:52:18 GMT</pubDate></item><item><title><![CDATA[Reply to DAMAGE: after normal block(xx) at (0xyy) on Fri, 07 May 2010 14:06:48 GMT]]></title><description><![CDATA[<p>_))) schrieb:</p>
<blockquote>
<p>So ein einfacher Fehler und keiner sieht ihn ^^</p>
<p>Ich hab ihn auch nicht gesehen.</p>
<p>gw,<br />
seldon</p>
</blockquote>
<p>dacht ich mir auch... -.-</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1893811</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1893811</guid><dc:creator><![CDATA[unskilled]]></dc:creator><pubDate>Fri, 07 May 2010 14:06:48 GMT</pubDate></item><item><title><![CDATA[Reply to DAMAGE: after normal block(xx) at (0xyy) on Fri, 07 May 2010 18:54:00 GMT]]></title><description><![CDATA[<p>Oh ja, da lag ich wohl voll daneben. Das wusste ich gar nicht, dass so auch der Fehler kommen kann.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1893964</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1893964</guid><dc:creator><![CDATA[Nukularfüsiker]]></dc:creator><pubDate>Fri, 07 May 2010 18:54:00 GMT</pubDate></item><item><title><![CDATA[Reply to DAMAGE: after normal block(xx) at (0xyy) on Mon, 10 May 2010 09:16:08 GMT]]></title><description><![CDATA[<p>Besten Dank!<br />
Das war mir noch gar nicht aufgefallen. Das alleine war zwar noch nicht die Lösung, da auch noch inhaltlich im Programm was schief lief.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1895013</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1895013</guid><dc:creator><![CDATA[Simpson84]]></dc:creator><pubDate>Mon, 10 May 2010 09:16:08 GMT</pubDate></item></channel></rss>