<html>
<head>
<base href="http://llvm.org/bugs/" />
</head>
<body><span class="vcard"><a class="email" href="mailto:mclow.lists@gmail.com" title="Marshall Clow (home) <mclow.lists@gmail.com>"> <span class="fn">Marshall Clow (home)</span></a>
</span> changed
<a class="bz_bug_link
bz_status_RESOLVED bz_closed"
title="RESOLVED INVALID - libc++ std::ostrstream leaks memory."
href="http://llvm.org/bugs/show_bug.cgi?id=22021">bug 22021</a>
<br>
<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>What</th>
<th>Removed</th>
<th>Added</th>
</tr>
<tr>
<td style="text-align:right;">Status</td>
<td>NEW
</td>
<td>RESOLVED
</td>
</tr>
<tr>
<td style="text-align:right;">Resolution</td>
<td>---
</td>
<td>INVALID
</td>
</tr></table>
<p>
<div>
<b><a class="bz_bug_link
bz_status_RESOLVED bz_closed"
title="RESOLVED INVALID - libc++ std::ostrstream leaks memory."
href="http://llvm.org/bugs/show_bug.cgi?id=22021#c1">Comment # 1</a>
on <a class="bz_bug_link
bz_status_RESOLVED bz_closed"
title="RESOLVED INVALID - libc++ std::ostrstream leaks memory."
href="http://llvm.org/bugs/show_bug.cgi?id=22021">bug 22021</a>
from <span class="vcard"><a class="email" href="mailto:mclow.lists@gmail.com" title="Marshall Clow (home) <mclow.lists@gmail.com>"> <span class="fn">Marshall Clow (home)</span></a>
</span></b>
<pre>This is a "required" memory leak (if you can believe that).
When you call strstreambuf::str() (which ostrstream is derived from), you get a
pointer to its internal buffer, and the stream is "frozen" (see
depr.strstreambuf.members/2 in the standard). Note that in spite of the method
being named "str", it does NOT return a std::string.
When the stream is destructed, the buffer may not be freed if the stream is
"frozen".
(see depr.strstreambuf.cons/8).
If you rewrite your code thus:
static std::string MessageComposer( uint32_t index )
{
std::ostrstream stm;
stm << "This is message #" << index << "." << std::endl;
std::string foo = stm.str();
stm.freeze(false);
return foo;
}
you will see that the "leak" has disappeared.
(Yeah, it's easy to misuse this object. Maybe that's why it is deprecated)</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>