This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [patch] temporary file handling


On Sun, Oct 10, 2010 at 01:42:58PM +0400, Vasiliy Kulikov wrote:
> diff -uNrp binutils-2.20.51.0.11.old/binutils/bucomm.c binutils-2.20.51.0.11/binutils/bucomm.c
> --- binutils-2.20.51.0.11.old/binutils/bucomm.c	2010-09-30 16:55:35.000000000 +0000
> +++ binutils-2.20.51.0.11/binutils/bucomm.c	2010-10-04 19:11:31.000000000 +0000
> @@ -491,19 +491,33 @@ template_in_dir (const char *path)
>  char *
>  make_tempname (char *filename)
>  {
> -  char *tmpname = template_in_dir (filename);
> +  char *tmpname;
>    int fd;
>  
>  #ifdef HAVE_MKSTEMP
> +  tmpname = template_in_dir (filename);
>    fd = mkstemp (tmpname);
>  #else
> -  tmpname = mktemp (tmpname);
> -  if (tmpname == NULL)
> -    return NULL;
> -  fd = open (tmpname, O_RDWR | O_CREAT | O_EXCL, 0600);
> +  int i;
> +  fd = -1;
> +  for (i = 0; i < 1000; i++)
> +    {
> +      tmpname = template_in_dir (filename);
> +      (void) mktemp (tmpname);
> +      if (tmpname[0] == 0)
> +        break;
> +      fd = open (tmpname, O_RDWR | O_CREAT | O_EXCL, 0600);
> +      if (fd != -1)
> +        break;
> +      free (tmpname);
> +      tmpname = NULL;
> +    }
>  #endif
>    if (fd == -1)
> -    return NULL;
> +    {
> +      free (tmpname);

Possible free(NULL) here and in make_tempdir, which may crash on some
older implementations of free.  We seem to worry about that
possibility elsewhere in binutils.

As the libiberty README says, libiberty patch should go to
gcc-patches@gcc.gnu.org, and maintainers of gcc and binutils generally
don't like #if 0 to remove code.  Even if this is fixed, I suspect
your patch will be rejected due to losing the capability to specify a
temp dir via the temp_base arg of pexecute.

-- 
Alan Modra
Australia Development Lab, IBM


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]