From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 30415 invoked by alias); 12 Sep 2011 19:06:19 -0000 Received: (qmail 30405 invoked by uid 22791); 12 Sep 2011 19:06:17 -0000 X-SWARE-Spam-Status: No, hits=-1.7 required=5.0 tests=AWL,BAYES_00,RCVD_NUMERIC_HELO,RP_MATCHES_RCVD,SPF_HELO_PASS,TW_BJ X-Spam-Check-By: sourceware.org Received: from lo.gmane.org (HELO lo.gmane.org) (80.91.229.12) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 12 Sep 2011 19:06:01 +0000 Received: from list by lo.gmane.org with local (Exim 4.69) (envelope-from ) id 1R3BpM-0005va-Aw for gdb-patches@sources.redhat.com; Mon, 12 Sep 2011 21:05:58 +0200 Received: from 209.226.137.108 ([209.226.137.108]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Mon, 12 Sep 2011 21:05:56 +0200 Received: from aristovski by 209.226.137.108 with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Mon, 12 Sep 2011 21:05:56 +0200 To: gdb-patches@sources.redhat.com From: Aleksandar Ristovski Subject: Re: dangling pointer in so_list Date: Mon, 12 Sep 2011 21:18:00 -0000 Message-ID: <4E6E57FE.4000409@qnx.com> References: <20110902201715.GA16280@host1.jankratochvil.net> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------080404080707050002000709" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:6.0.2) Gecko/20110906 Thunderbird/6.0.2 In-Reply-To: <20110902201715.GA16280@host1.jankratochvil.net> X-IsSubscribed: yes 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 X-SW-Source: 2011-09/txt/msg00204.txt.bz2 This is a multi-part message in MIME format. --------------080404080707050002000709 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-length: 568 On 11-09-02 04:17 PM, Jan Kratochvil wrote: > > Use some solib-identifying name (such as the common solib_ prefix). > > OK without the `head' parameter and with the solib_ prefix. > I have committed this now with the solib_ prefix and body of the function as suggested. Attached is the final patch/ChangeLog for reference. Thank you, Aleksandar Ristovski QNX Software Systems ChangeLog: * solib.c (solib_used): New function. (update_solib_list, reload_shared_libraries_1): Check if objfile is used by another so_list object before freeing it. --------------080404080707050002000709 Content-Type: text/x-patch; name="dangling_objfile_in_so_list-201109121421.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="dangling_objfile_in_so_list-201109121421.patch" Content-length: 1689 Index: gdb/solib.c =================================================================== RCS file: /cvs/src/src/gdb/solib.c,v retrieving revision 1.153 diff -u -p -r1.153 solib.c --- gdb/solib.c 30 Aug 2011 02:48:05 -0000 1.153 +++ gdb/solib.c 12 Sep 2011 18:21:42 -0000 @@ -633,6 +633,20 @@ solib_read_symbols (struct so_list *so, return 0; } +/* Return 1 if KNOWN->objfile is used by any other so_list object in the + SO_LIST_HEAD list. Return 0 otherwise. */ + +static int +solib_used (const struct so_list *const known) +{ + const struct so_list *pivot; + + for (pivot = so_list_head; pivot != NULL; pivot = pivot->next) + if (pivot != known && pivot->objfile == known->objfile) + return 1; + return 0; +} + /* Synchronize GDB's shared object list with inferior's. Extract the list of currently loaded shared objects from the @@ -749,7 +763,8 @@ update_solib_list (int from_tty, struct *gdb_link = gdb->next; /* Unless the user loaded it explicitly, free SO's objfile. */ - if (gdb->objfile && ! (gdb->objfile->flags & OBJF_USERLOADED)) + if (gdb->objfile && ! (gdb->objfile->flags & OBJF_USERLOADED) + && !solib_used (gdb)) free_objfile (gdb->objfile); /* Some targets' section tables might be referring to @@ -1225,7 +1240,8 @@ reload_shared_libraries_1 (int from_tty) || (found_pathname != NULL && filename_cmp (found_pathname, so->so_name) != 0)) { - if (so->objfile && ! (so->objfile->flags & OBJF_USERLOADED)) + if (so->objfile && ! (so->objfile->flags & OBJF_USERLOADED) + && !solib_used (so)) free_objfile (so->objfile); remove_target_sections (so->abfd); free_so_symbols (so); --------------080404080707050002000709--