From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 122909 invoked by alias); 29 Jul 2017 23:54:47 -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 122887 invoked by uid 89); 29 Jul 2017 23:54:46 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.3 required=5.0 tests=AWL,BAYES_00,RP_MATCHES_RCVD,SPF_HELO_PASS,SPF_PASS autolearn=ham version=3.3.2 spammy=Hx-languages-length:1948 X-HELO: smtp.polymtl.ca Received: from smtp.polymtl.ca (HELO smtp.polymtl.ca) (132.207.4.11) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sat, 29 Jul 2017 23:54:45 +0000 Received: from simark.ca (simark.ca [158.69.221.121]) (authenticated bits=0) by smtp.polymtl.ca (8.14.7/8.14.7) with ESMTP id v6TNscZs024060 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Sat, 29 Jul 2017 19:54:43 -0400 Received: by simark.ca (Postfix, from userid 112) id 969701EA05; Sat, 29 Jul 2017 19:54:38 -0400 (EDT) Received: from simark.ca (localhost [127.0.0.1]) by simark.ca (Postfix) with ESMTP id DC9951E043; Sat, 29 Jul 2017 19:54:36 -0400 (EDT) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII; format=flowed Content-Transfer-Encoding: 7bit Date: Sat, 29 Jul 2017 23:54:00 -0000 From: Simon Marchi To: Tom Tromey Cc: gdb-patches@sourceware.org Subject: Re: [RFA v2 03/24] Change return type of find_and_open_script In-Reply-To: <20170725172107.9799-4-tom@tromey.com> References: <20170725172107.9799-1-tom@tromey.com> <20170725172107.9799-4-tom@tromey.com> Message-ID: <2fed0a72cbcbf472906e4c4966cde63b@polymtl.ca> X-Sender: simon.marchi@polymtl.ca User-Agent: Roundcube Webmail/1.3.0 X-Poly-FromMTA: (simark.ca [158.69.221.121]) at Sat, 29 Jul 2017 23:54:38 +0000 X-IsSubscribed: yes X-SW-Source: 2017-07/txt/msg00437.txt.bz2 Hi Tom, I like the change, but one thing caught my attention. On 2017-07-25 19:20, Tom Tromey wrote: > @@ -953,26 +950,25 @@ source_script_file (struct auto_load_pspace_info > *pspace_info, > return; > } > > - opened = find_and_open_script (file, 1 /*search_path*/, > - &stream, &full_path); > + gdb::optional opened = find_and_open_script (file, > + 1 /*search_path*/); > + const char *path_ptr; > > - cleanups = make_cleanup (null_cleanup, NULL); > if (opened) > { > - make_cleanup_fclose (stream); > - make_cleanup (xfree, full_path); > - > - if (!file_is_auto_load_safe (full_path, > + path_ptr = opened->full_path.get (); > + if (!file_is_auto_load_safe (opened->full_path.get (), > _("auto-load: Loading %s script " > "\"%s\" from section \"%s\" of " > "objfile \"%s\".\n"), > - ext_lang_name (language), full_path, > + ext_lang_name (language), > + opened->full_path.get (), > section_name, objfile_name (objfile))) > - opened = 0; > + opened.reset (); > } > else > { > - full_path = NULL; > + path_ptr = NULL; > > /* If one script isn't found it's not uncommon for more to not > be > found either. We don't want to print a message for each script, > @@ -986,14 +982,12 @@ source_script_file (struct auto_load_pspace_info > *pspace_info, > section_name, offset); > } > > - in_hash_table = maybe_add_script_file (pspace_info, opened, file, > full_path, > - language); > + in_hash_table = maybe_add_script_file (pspace_info, bool (opened), > file, > + path_ptr, language); Here, isn't path_ptr used after free in case the auto-load was denied? > > /* If this file is not currently loaded, load it. */ > if (opened && !in_hash_table) > - sourcer (language, objfile, stream, full_path); > - > - do_cleanups (cleanups); > + sourcer (language, objfile, opened->stream.get (), path_ptr); > } > > /* Subroutine of source_section_scripts to simplify it. Thanks, Simon