From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 16874 invoked by alias); 20 Feb 2018 12:48:54 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 15196 invoked by uid 89); 20 Feb 2018 12:48:48 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.7 required=5.0 tests=RCVD_IN_DNSWL_LOW,TIME_LIMIT_EXCEEDED autolearn=unavailable version=3.3.2 spammy= X-Spam-User: qpsmtpd, 2 recipients X-HELO: mx1.redhat.com Received: from mx3-rdu2.redhat.com (HELO mx1.redhat.com) (66.187.233.73) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 20 Feb 2018 12:48:37 +0000 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0BBED407A9AA; Tue, 20 Feb 2018 12:48:25 +0000 (UTC) Received: from [10.36.117.61] (ovpn-117-61.ams2.redhat.com [10.36.117.61]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3660A2024CA6; Tue, 20 Feb 2018 12:48:24 +0000 (UTC) Subject: Re: RFA: Sanitize deprecation messages (PR 84195) To: Martin Sebor , David Malcolm , msebor@gcc.gnu.org Cc: dodji@redhat.com, gcc-patches@gcc.gnu.org References: <87h8qv9xhb.fsf@redhat.com> <79784243-bf45-167f-a546-55c892ea02e9@gmail.com> <93d668b3-30d1-e898-544f-19a153325e03@redhat.com> <1518031052.26503.90.camel@redhat.com> <0d7e6077-0d67-0c7b-5058-fc66e7c18d87@gmail.com> <1518728685.2913.14.camel@redhat.com> <490266ba-d4c5-2016-6a0f-bc0178f834a0@gmail.com> From: Nick Clifton Message-ID: <8ed3cc4d-82cc-4c99-8dbe-e18c949d5c6f@redhat.com> Date: Tue, 20 Feb 2018 12:48:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.5.2 MIME-Version: 1.0 In-Reply-To: <490266ba-d4c5-2016-6a0f-bc0178f834a0@gmail.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-IsSubscribed: yes X-SW-Source: 2018-02/txt/msg01159.txt.bz2 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