Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: dje@google.com (Doug Evans)
To: gdb-patches@sourceware.org
Subject: [RFA] source.c:find_and_open_source cleanup
Date: Mon, 07 Apr 2008 22:26:00 -0000	[thread overview]
Message-ID: <20080407193412.3CDC11C751F@localhost> (raw)

This is odd:

  if (result >= 0)
    {
      char *tmp_fullname;
      tmp_fullname = *fullname;
      *fullname = xstrdup (tmp_fullname);
      xfree (tmp_fullname);
    }

Is there something subtle going on here?
I thought maybe the caller might be expecting a newly allocated value
if it passed in a value for `fullname', but the previous value has
already been freed at this point.

2008-04-07  Doug Evans  <dje@google.com>

	* source.c (find_and_open_source): Add some comments clarifying
	handling of FULLNAME argument.	Make static.  Remove pointless
	xstrdup/xfree.

Index: source.c
===================================================================
RCS file: /cvs/src/src/gdb/source.c,v
retrieving revision 1.86
diff -u -p -u -p -r1.86 source.c
--- source.c	14 Mar 2008 18:39:43 -0000	1.86
+++ source.c	7 Apr 2008 19:30:01 -0000
@@ -927,15 +927,19 @@ rewrite_source_path (const char *path)
    DIRNAME is the compilation directory of a particular source file.
            Only some debug formats provide this info.
    FULLNAME can be the last known absolute path to the file in question.
+     Space for the path must have been malloc'd.  If a path substitution
+     is applied we free the old value and set a new one.
 
    On Success 
      A valid file descriptor is returned. ( the return value is positive )
      FULLNAME is set to the absolute path to the file just opened.
+     The caller is responsible for freeing FULLNAME.
 
    On Failure
      An invalid file descriptor is returned. ( the return value is negative ) 
      FULLNAME is set to NULL.  */
-int
+
+static int
 find_and_open_source (struct objfile *objfile,
 		      const char *filename,
 		      const char *dirname,
@@ -1022,13 +1026,6 @@ find_and_open_source (struct objfile *ob
 	result = openp (path, OPF_SEARCH_IN_PATH, p, OPEN_MODE, 0, fullname);
     }
 
-  if (result >= 0)
-    {
-      char *tmp_fullname;
-      tmp_fullname = *fullname;
-      *fullname = xstrdup (tmp_fullname);
-      xfree (tmp_fullname);
-    }
   return result;
 }
 


             reply	other threads:[~2008-04-07 19:34 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-04-07 22:26 Doug Evans [this message]
2008-04-07 22:56 ` Doug Evans
2008-04-17 16:15 ` Daniel Jacobowitz

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=20080407193412.3CDC11C751F@localhost \
    --to=dje@google.com \
    --cc=gdb-patches@sourceware.org \
    /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