Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: msnyder@sonic.net
To: "Jim Blandy" <jimb@codesourcery.com>
Cc: gdb-patches@sourceware.org
Subject: Re: [PATCH] solib_open, memory leak
Date: Wed, 08 Aug 2007 21:58:00 -0000	[thread overview]
Message-ID: <22684.12.7.175.2.1186610277.squirrel@webmail.sonic.net> (raw)
In-Reply-To: <m34pj9vgvr.fsf@codesourcery.com>

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

[Jim:]
> The code clearly deserves a comment like:
>
>     /* We try to find the library in various ways.  After each
>        attempt, either found_file >= 0 and temp_pathname is a malloc'd
>        string, or found_file < 0 and temp_pathname does not point to
>        storage that needs to be freed.  */
>
> In that light, it seems clearer to me to just put:
>
>    if (found_file < 0)
>      temp_pathname = NULL;
>    else
>      temp_pathname = xstrdup (temp_pathname);
>
> immediately after the open, to make it obvious that the rule is
> followed there.
>
[...]
> Don't you want those new lines to replace the two that followed them,
> not just precede them?

Yes, thanks.  How about this?


[-- Attachment #2: solib_open2.txt --]
[-- Type: text/plain, Size: 1692 bytes --]

Index: solib.c
===================================================================
RCS file: /cvs/src/src/gdb/solib.c,v
retrieving revision 1.94
diff -p -r1.94 solib.c
*** solib.c	3 Jul 2007 12:14:43 -0000	1.94
--- solib.c	8 Aug 2007 21:57:27 -0000
*************** solib_open (char *in_pathname, char **fo
*** 176,181 ****
--- 176,192 ----
    /* Now see if we can open it.  */
    found_file = open (temp_pathname, O_RDONLY | O_BINARY, 0);
  
+   /* We try to find the library in various ways.  After each attempt
+      (except for the one above), either found_file >= 0 and
+      temp_pathname is a malloc'd string, or found_file < 0 and
+      temp_pathname does not point to storage that needs to be
+      freed.  */
+ 
+     if (found_file < 0)
+       temp_pathname = NULL;
+     else
+       temp_pathname = xstrdup (temp_pathname);
+ 
    /* If the search in gdb_sysroot failed, and the path name is
       absolute at this point, make it relative.  (openp will try and open the
       file according to its absolute path otherwise, which is not what we want.)
*************** solib_open (char *in_pathname, char **fo
*** 224,231 ****
  
    /* Done.  If not found, tough luck.  Return found_file and 
       (optionally) found_pathname.  */
!   if (found_pathname != NULL && temp_pathname != NULL)
!     *found_pathname = xstrdup (temp_pathname);
    return found_file;
  }
  
--- 235,247 ----
  
    /* Done.  If not found, tough luck.  Return found_file and 
       (optionally) found_pathname.  */
!   if (temp_pathname)
!     {
!       if (found_pathname != NULL)
! 	*found_pathname = temp_pathname;
!       else
! 	xfree (temp_pathname);
!     }
    return found_file;
  }
  

  reply	other threads:[~2007-08-08 21:58 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-08-05  3:17 msnyder
2007-08-06 22:28 ` Jim Blandy
2007-08-06 22:39   ` Kevin Buettner
2007-08-08 18:29   ` msnyder
2007-08-08 21:46     ` Jim Blandy
2007-08-08 21:58       ` msnyder [this message]
2007-08-08 22:08         ` Jim Blandy
2007-08-09 18:37           ` msnyder

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=22684.12.7.175.2.1186610277.squirrel@webmail.sonic.net \
    --to=msnyder@sonic.net \
    --cc=gdb-patches@sourceware.org \
    --cc=jimb@codesourcery.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