Discussion:
How to avoid leaking facets when creating locales
(too old to reply)
stephan.bergmann.secondary via ISO C++ Standard - Discussion
2018-11-05 10:44:54 UTC
Permalink
When using the (non-noexcept, [locale.cons])

template<class Facet> locale(const locale& other, Facet* f)

std::locale constructor template as in

std::locale(std::locale(), new std::ctype<char>)

I think there is a chance that the outer locale constructor can throw an
exception and cause the heap-allocated ctype instance to leak? (The inner
locale default constructor is noexcept, but the outer one isn't, though its
description doesn't specify under what conditions it might throw an
exception. Also, it is not clear to me whether or not the constructor
would have to take over responsibility of managing the passed-in facets
lifetime in case the constructor throws an exception. Making it the
responsibility of the calling code would be awkward, as the
std::ctype<char> destructor is protected, so calling code would have to (a)
define a derived class solely to be able to call the destructor in case of
an exception, and (b) use some RAII or try/catch to manually destroy the
facet iff an exception is thrown.)

Any thoughts?
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-discussion+***@isocpp.org.
To post to this group, send email to std-***@isocpp.org.
Visit this group at https://groups.google.com/a/isocpp.org/group/std-discussion/.
Tony V E
2018-11-05 12:21:34 UTC
Permalink
<html><head></head><body lang="en-US" style="background-color: rgb(255, 255, 255); line-height: initial;"> <div style="width: 100%; font-size: initial; font-family: Calibri, 'Slate Pro', sans-serif, sans-serif; color: rgb(31, 73, 125); text-align: initial; background-color: rgb(255, 255, 255);">Leaking facets?</div><div style="width: 100%; font-size: initial; font-family: Calibri, 'Slate Pro', sans-serif, sans-serif; color: rgb(31, 73, 125); text-align: initial; background-color: rgb(255, 255, 255);">Call a plumber?</div><div style="width: 100%; font-size: initial; font-family: Calibri, 'Slate Pro', sans-serif, sans-serif; color: rgb(31, 73, 125); text-align: initial; background-color: rgb(255, 255, 255);"><br></div> <div style="width: 100%; font-size: initial; font-family: Calibri, 'Slate Pro', sans-serif, sans-serif; color: rgb(31, 73, 125); text-align: initial; background-color: rgb(255, 255, 255);"><br style="display:initial"></div> <div style="font-size: initial; font-family: Calibri, 'Slate Pro', sans-serif, sans-serif; color: rgb(31, 73, 125); text-align: initial; background-color: rgb(255, 255, 255);">Sent&nbsp;from&nbsp;my&nbsp;BlackBerry&nbsp;portable&nbsp;Babbage&nbsp;Device</div> <table width="100%" style="background-color:white;border-spacing:0px;"> <tbody><tr><td colspan="2" style="font-size: initial; text-align: initial; background-color: rgb(255, 255, 255);"> <div style="border-style: solid none none; border-top-color: rgb(181, 196, 223); border-top-width: 1pt; padding: 3pt 0in 0in; font-family: Tahoma, 'BB Alpha Sans', 'Slate Pro'; font-size: 10pt;"> <div><b>From: </b>stephan.bergmann.secondary via ISO C++ Standard - Discussion</div><div><b>Sent: </b>Monday, November 5, 2018 5:44 AM</div><div><b>To: </b>ISO C++ Standard - Discussion</div><div><b>Reply To: </b>std-***@isocpp.org</div><div><b>Subject: </b>[std-discussion] How to avoid leaking facets when creating locales</div></div></td></tr></tbody></table><div style="border-style: solid none none; border-top-color: rgb(186, 188, 209); border-top-width: 1pt; font-size: initial; text-align: initial; background-color: rgb(255, 255, 255);"></div><br><div id="_originalContent" style=""><div dir="ltr"><div>When using the (non-noexcept, [locale.cons])</div><div><br></div><div>&nbsp; template&lt;class Facet&gt; locale(const locale&amp; other, Facet* f)</div><div><br></div><div>std::locale constructor template as in</div><div><br></div><div>&nbsp; std::locale(std::locale(), new std::ctype&lt;char&gt;)</div><div><br></div><div>I think there is a chance that the outer locale constructor can throw an exception and cause the heap-allocated ctype instance to leak?&nbsp; (The inner locale default constructor is noexcept, but the outer one isn't, though its description doesn't specify under what conditions it might throw an exception.&nbsp; Also, it is not clear to me whether or not the constructor would have to take over responsibility of managing the passed-in facets lifetime in case the constructor throws an exception.&nbsp; Making it the responsibility of the calling code would be awkward, as the std::ctype&lt;char&gt; destructor is protected, so calling code would have to (a) define a derived class solely to be able to call the destructor in case of an exception, and (b) use some RAII or try/catch to manually destroy the facet iff an exception is thrown.)</div><div><br></div><div>Any thoughts?<br></div></div>

<p></p>

-- <br>
<br>
--- <br>
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Discussion" group.<br>
To unsubscribe from this group and stop receiving emails from it, send an email to <a href="mailto:std-discussion+***@isocpp.org">std-discussion+***@isocpp.org</a>.<br>
To post to this group, send email to <a href="mailto:std-***@isocpp.org">std-***@isocpp.org</a>.<br>
Visit this group at <a href="https://groups.google.com/a/isocpp.org/group/std-discussion/">https://groups.google.com/a/isocpp.org/group/std-discussion/</a>.<br>
<br><!--end of _originalContent --></div></body></html>

<p></p>

-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &quot;ISO C++ Standard - Discussion&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an email to <a href="mailto:std-discussion+***@isocpp.org">std-discussion+***@isocpp.org</a>.<br />
To post to this group, send email to <a href="mailto:std-***@isocpp.org">std-***@isocpp.org</a>.<br />
Visit this group at <a href="https://groups.google.com/a/isocpp.org/group/std-discussion/">https://groups.google.com/a/isocpp.org/group/std-discussion/</a>.<br />
Continue reading on narkive:
Loading...