mirror of
https://github.com/espressif/binutils-gdb.git
synced 2025-06-21 02:24:17 +08:00
PR29255, memory leak in make_tempdir
PR 29255 * bucomm.c (make_tempdir, make_tempname): Free template on all failure paths.
This commit is contained in:
@ -537,7 +537,8 @@ make_tempname (const char *filename, int *ofd)
|
|||||||
#else
|
#else
|
||||||
tmpname = mktemp (tmpname);
|
tmpname = mktemp (tmpname);
|
||||||
if (tmpname == NULL)
|
if (tmpname == NULL)
|
||||||
return NULL;
|
fd = -1;
|
||||||
|
else
|
||||||
fd = open (tmpname, O_RDWR | O_CREAT | O_EXCL, 0600);
|
fd = open (tmpname, O_RDWR | O_CREAT | O_EXCL, 0600);
|
||||||
#endif
|
#endif
|
||||||
if (fd == -1)
|
if (fd == -1)
|
||||||
@ -556,22 +557,23 @@ char *
|
|||||||
make_tempdir (const char *filename)
|
make_tempdir (const char *filename)
|
||||||
{
|
{
|
||||||
char *tmpname = template_in_dir (filename);
|
char *tmpname = template_in_dir (filename);
|
||||||
|
char *ret;
|
||||||
|
|
||||||
#ifdef HAVE_MKDTEMP
|
#ifdef HAVE_MKDTEMP
|
||||||
return mkdtemp (tmpname);
|
ret = mkdtemp (tmpname);
|
||||||
#else
|
#else
|
||||||
tmpname = mktemp (tmpname);
|
ret = mktemp (tmpname);
|
||||||
if (tmpname == NULL)
|
|
||||||
return NULL;
|
|
||||||
#if defined (_WIN32) && !defined (__CYGWIN32__)
|
#if defined (_WIN32) && !defined (__CYGWIN32__)
|
||||||
if (mkdir (tmpname) != 0)
|
if (mkdir (tmpname) != 0)
|
||||||
return NULL;
|
ret = NULL;
|
||||||
#else
|
#else
|
||||||
if (mkdir (tmpname, 0700) != 0)
|
if (mkdir (tmpname, 0700) != 0)
|
||||||
return NULL;
|
ret = NULL;
|
||||||
#endif
|
#endif
|
||||||
return tmpname;
|
|
||||||
#endif
|
#endif
|
||||||
|
if (ret == NULL)
|
||||||
|
free (tmpname);
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Parse a string into a VMA, with a fatal error if it can't be
|
/* Parse a string into a VMA, with a fatal error if it can't be
|
||||||
|
Reference in New Issue
Block a user