Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Aleksandar Ristovski <aristovski@qnx.com>
To: gdb-patches@sources.redhat.com
Subject: Re: dangling pointer in so_list
Date: Mon, 12 Sep 2011 21:18:00 -0000	[thread overview]
Message-ID: <4E6E57FE.4000409@qnx.com> (raw)
In-Reply-To: <20110902201715.GA16280@host1.jankratochvil.net>

[-- Attachment #1: Type: text/plain, Size: 568 bytes --]

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.

[-- Attachment #2: dangling_objfile_in_so_list-201109121421.patch --]
[-- Type: text/x-patch, Size: 1689 bytes --]

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);

      reply	other threads:[~2011-09-12 19:06 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-08-31 20:01 Aleksandar Ristovski
2011-08-31 20:12 ` Aleksandar Ristovski
2011-09-02 13:52   ` Aleksandar Ristovski
2011-09-02 20:45     ` Jan Kratochvil
2011-09-12 21:18       ` Aleksandar Ristovski [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4E6E57FE.4000409@qnx.com \
    --to=aristovski@qnx.com \
    --cc=gdb-patches@sources.redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox