From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 24959 invoked by alias); 30 Jan 2015 16:41:56 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 24921 invoked by uid 89); 30 Jan 2015 16:41:54 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.0 required=5.0 tests=AWL,BAYES_00,SPF_PASS autolearn=ham version=3.3.2 X-HELO: usevmg21.ericsson.net Received: from usevmg21.ericsson.net (HELO usevmg21.ericsson.net) (198.24.6.65) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-SHA encrypted) ESMTPS; Fri, 30 Jan 2015 16:41:52 +0000 Received: from EUSAAHC008.ericsson.se (Unknown_Domain [147.117.188.96]) by usevmg21.ericsson.net (Symantec Mail Security) with SMTP id 57.EA.25146.F155BC45; Fri, 30 Jan 2015 10:55:43 +0100 (CET) Received: from [142.133.110.232] (147.117.188.8) by smtp-am.internal.ericsson.com (147.117.188.98) with Microsoft SMTP Server id 14.3.195.1; Fri, 30 Jan 2015 11:41:48 -0500 Message-ID: <54CBB44C.8040701@ericsson.com> Date: Fri, 30 Jan 2015 20:10:00 -0000 From: Simon Marchi User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.3.0 MIME-Version: 1.0 To: Joel Brobecker CC: Subject: Re: [PATCH 2/6] Mention which return values need to be freed in lang_varobj_ops References: <1422559716-5480-1-git-send-email-simon.marchi@ericsson.com> <1422559716-5480-2-git-send-email-simon.marchi@ericsson.com> <20150130032848.GK5193@adacore.com> In-Reply-To: <20150130032848.GK5193@adacore.com> Content-Type: text/plain; charset="windows-1252" Content-Transfer-Encoding: 7bit X-IsSubscribed: yes X-SW-Source: 2015-01/txt/msg00798.txt.bz2 On 15-01-29 10:28 PM, Joel Brobecker wrote: >> gdb/ChangeLog: >> >> * varobj.h (lang_varobj_ops): Mention which return values need >> to be freed. > > Thanks for doing that! One question... > >> - /* The ``struct value *'' of the INDEX'th child of PARENT. */ >> + /* The ``struct value *'' of the INDEX'th child of PARENT. The returned >> + value must be freed by the caller. */ >> struct value *(*value_of_child) (struct varobj *parent, int index); > > I'm really surprised by this. For memory management, the struct value > objects are put on a chain. So, you wouldn't delete the value returned, > but you would instead use "value_mark/value_free_to_mark". The top-level > command loop takes a mark at the beginning of the command, and uses it > to free any un-freed value after the command completes. > > But maybe you saw something that contradicts my understanding? After looking more closely, I think you are right. Originally, I saw that install_new_value called value_free on the old value and jumped to the conclusion. Actually, value_free is more like a "value_decref", which frees the variable if the reference count drops to 0. The call to value_free just matches the value_incref that was also done in install_new_value when we installed the value. So just calling value_of_child doesn't mean that you have to call value_free. Thanks for the explanation, I didn't know about the memory management of values. I'll remove the comment change for value_of_child. Is the rest of the patch ok?