This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: RFA: Sanitize deprecation messages (PR 84195)
Hi Martin,
> Since the class manages a resource it should ideally make sure it
> doesn't try to release the same resource multiple times. I.e., its
> copy constructor and assignment operators should either "do the right
> thing" (whatever you think that is) or be made inaccessible (or declared deleted in C++ 11).
>
> For example:
>
> {
> escaped_string a;
> a.escape ("foo\nbar");
>
> escaped_string b (a);
> // b destroys its m_str
> // double free in a's destructor here
> }
I am not sure that this can happen. First of the escaped_string
class does not have constructor that accepts a char* argument.
(Maybe in C++ this is done automatically ? My C++-fu is very weak).
Secondly the m_owned private field is only set to true when
the m_str field is set to a string allocated by the particular
instance of the class, and memory is only freed by the destructor
if m_owned is true.
So even this should work:
{
escaped_string a,b;
a.escape ("foo\nbar");
b.escape ((const char *) a);
}
The destructor for B will not free any memory, even though its
m_str field has been set to the same string as A, because its
m_owned field will be set to FALSE.
Cheers
Nick