From patchwork Tue Jan 27 18:33:38 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Marchi X-Patchwork-Id: 4830 Received: (qmail 26966 invoked by alias); 27 Jan 2015 18:33:47 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 26938 invoked by uid 89); 27 Jan 2015 18:33:46 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-1.0 required=5.0 tests=AWL, 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; Tue, 27 Jan 2015 18:33:45 +0000 Received: from EUSAAHC002.ericsson.se (Unknown_Domain [147.117.188.78]) by usevmg21.ericsson.net (Symantec Mail Security) with SMTP id 99.F7.25146.EFA77C45; Tue, 27 Jan 2015 12:48:14 +0100 (CET) Received: from elxcz23q12-y4.mo.ca.am.ericsson.se (147.117.188.8) by smtps-am.internal.ericsson.com (147.117.188.78) with Microsoft SMTP Server (TLS) id 14.3.195.1; Tue, 27 Jan 2015 13:33:41 -0500 From: Simon Marchi To: CC: Simon Marchi Subject: [PATCH] Free results of varobj_get_type and type_to_string Date: Tue, 27 Jan 2015 13:33:38 -0500 Message-ID: <1422383618-8215-1-git-send-email-simon.marchi@ericsson.com> MIME-Version: 1.0 X-IsSubscribed: yes varobj_get_type and type_to_string return an allocated string, which is not freed at a couple of places. gdb/ChangeLog: * mi/mi-cmd-var.c (mi_cmd_var_info_type): Free result of varobj_get_type. (varobj_update_one): Same. * varobj.c (update_type_if_necessary): Free curr_type_str and new_type_str. (varobj_get_type): Specify in comment that the result needs to be freed by the caller. --- gdb/mi/mi-cmd-var.c | 12 ++++++++++-- gdb/varobj.c | 5 ++++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/gdb/mi/mi-cmd-var.c b/gdb/mi/mi-cmd-var.c index 01838b1..4aabb57 100644 --- a/gdb/mi/mi-cmd-var.c +++ b/gdb/mi/mi-cmd-var.c @@ -447,14 +447,18 @@ mi_cmd_var_info_type (char *command, char **argv, int argc) { struct ui_out *uiout = current_uiout; struct varobj *var; + char *type; if (argc != 1) error (_("-var-info-type: Usage: NAME.")); /* Get varobj handle, if a valid var obj name was specified. */ var = varobj_get_handle (argv[0]); + type = varobj_get_type (var); + + ui_out_field_string (uiout, "type", type); - ui_out_field_string (uiout, "type", varobj_get_type (var)); + xfree (type); } void @@ -765,7 +769,11 @@ varobj_update_one (struct varobj *var, enum print_values print_values, } if (r->type_changed) - ui_out_field_string (uiout, "new_type", varobj_get_type (r->varobj)); + { + char *type = varobj_get_type (r->varobj); + ui_out_field_string (uiout, "new_type", type); + xfree (type); + } if (r->type_changed || r->children_changed) ui_out_field_int (uiout, "new_num_children", diff --git a/gdb/varobj.c b/gdb/varobj.c index a10560f..9735958 100644 --- a/gdb/varobj.c +++ b/gdb/varobj.c @@ -972,7 +972,8 @@ varobj_add_child (struct varobj *var, struct varobj_item *item) } /* Obtain the type of an object Variable as a string similar to the one gdb - prints on the console. */ + prints on the console. The caller is responsible for freeing the string. + */ char * varobj_get_type (struct varobj *var) @@ -1303,6 +1304,8 @@ update_type_if_necessary (struct varobj *var, struct value *new_value) var->num_children = -1; return 1; } + xfree (curr_type_str); + xfree (new_type_str); } }