<?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[Speicher innerhalb einer std::list freigeben]]></title><description><![CDATA[<p>Hallo!</p>
<p>Ich habe ein Problem bei der Freigabe von Speicher in einer std::list.</p>
<pre><code>...
struct TEXTURE
{
	LPDIRECT3DTEXTURE9	texture;
	char			*filename;
};
...
std::list&lt;TEXTURE&gt; textures;
TEXTURE texture;
...
texture.filename = new char[strlen(Dateiname)];
strcpy(texture.filename, Dateiname);
textures.push_front(texture);
...
for(std::list&lt;TEXTURE&gt;::iterator it = textures.begin();
	it != textures.end(); it++)
{
	...
	delete[] it-&gt;filename;
	...
}
textures.clear();
...
</code></pre>
<p>Ich muss ja den zugewiesenen Speicher für 'filename' wieder freigeben, bekomme aber eine 'Heap-Corruption'-Fehlermeldung in Zeile 19 (delete[]).</p>
<p>Was mache ich falsch?</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/325037/speicher-innerhalb-einer-std-list-freigeben</link><generator>RSS for Node</generator><lastBuildDate>Mon, 13 Jul 2026 11:12:00 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/325037.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 11 Apr 2014 23:03:03 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Speicher innerhalb einer std::list freigeben on Fri, 11 Apr 2014 23:03:03 GMT]]></title><description><![CDATA[<p>Hallo!</p>
<p>Ich habe ein Problem bei der Freigabe von Speicher in einer std::list.</p>
<pre><code>...
struct TEXTURE
{
	LPDIRECT3DTEXTURE9	texture;
	char			*filename;
};
...
std::list&lt;TEXTURE&gt; textures;
TEXTURE texture;
...
texture.filename = new char[strlen(Dateiname)];
strcpy(texture.filename, Dateiname);
textures.push_front(texture);
...
for(std::list&lt;TEXTURE&gt;::iterator it = textures.begin();
	it != textures.end(); it++)
{
	...
	delete[] it-&gt;filename;
	...
}
textures.clear();
...
</code></pre>
<p>Ich muss ja den zugewiesenen Speicher für 'filename' wieder freigeben, bekomme aber eine 'Heap-Corruption'-Fehlermeldung in Zeile 19 (delete[]).</p>
<p>Was mache ich falsch?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2394128</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2394128</guid><dc:creator><![CDATA[Starcluster]]></dc:creator><pubDate>Fri, 11 Apr 2014 23:03:03 GMT</pubDate></item><item><title><![CDATA[Reply to Speicher innerhalb einer std::list freigeben on Fri, 11 Apr 2014 23:04:42 GMT]]></title><description><![CDATA[<p>Starcluster schrieb:</p>
<blockquote>
<p>Was mache ich falsch?</p>
</blockquote>
<p>Du verwendest <code>new</code> und <code>strcpy</code> statt <code>std::string</code> .</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2394129</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2394129</guid><dc:creator><![CDATA[TyRoXx]]></dc:creator><pubDate>Fri, 11 Apr 2014 23:04:42 GMT</pubDate></item><item><title><![CDATA[Reply to Speicher innerhalb einer std::list freigeben on Fri, 11 Apr 2014 23:05:15 GMT]]></title><description><![CDATA[<p>1. std::string statt char-pointer löst das problem.<br />
2. wieso std::list? du suchst std::vector</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2394130</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2394130</guid><dc:creator><![CDATA[Fytch]]></dc:creator><pubDate>Fri, 11 Apr 2014 23:05:15 GMT</pubDate></item><item><title><![CDATA[Reply to Speicher innerhalb einer std::list freigeben on Fri, 11 Apr 2014 23:25:08 GMT]]></title><description><![CDATA[<p>Ah, ich Idiot ;).<br />
Danke für die schnelle Hilfe!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2394135</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2394135</guid><dc:creator><![CDATA[Starcluster]]></dc:creator><pubDate>Fri, 11 Apr 2014 23:25:08 GMT</pubDate></item><item><title><![CDATA[Reply to Speicher innerhalb einer std::list freigeben on Sun, 13 Apr 2014 16:51:01 GMT]]></title><description><![CDATA[<p>Starcluster schrieb:</p>
<blockquote>
<p>Hallo!</p>
<p>Ich habe ein Problem bei der Freigabe von Speicher in einer std::list.</p>
<pre><code>...
texture.filename = new char[strlen(Dateiname)];
strcpy(texture.filename, Dateiname);
</code></pre>
</blockquote>
<p><img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/26a0.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--warning"
      title=":warning:"
      alt="⚠"
    /> Achtung: buffer overflow <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/26a0.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--warning"
      title=":warning:"
      alt="⚠"
    /><br />
<code>strlen(Dateiname)</code> liefert die Anzahl der Zeichen. <code>strcpy</code> Kopiert die Zeichen und hängt noch ein '\0' dran.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2394407</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2394407</guid><dc:creator><![CDATA[tntnet]]></dc:creator><pubDate>Sun, 13 Apr 2014 16:51:01 GMT</pubDate></item></channel></rss>