Plug default_PATH memory leak
* src/emacs.c (default_PATH): Fix very-unlikely memory leak.
This commit is contained in:
parent
1eb2e052bb
commit
59b2f8f1dc
1 changed files with 12 additions and 9 deletions
21
src/emacs.c
21
src/emacs.c
|
|
@ -753,21 +753,24 @@ default_PATH (void)
|
|||
{
|
||||
#ifdef _CS_PATH
|
||||
char *buf = staticbuf;
|
||||
size_t bufsize = sizeof staticbuf, s;
|
||||
size_t bufsize = sizeof staticbuf;
|
||||
|
||||
/* If necessary call confstr a second time with a bigger buffer. */
|
||||
while (bufsize < (s = confstr (_CS_PATH, buf, bufsize)))
|
||||
/* If necessary call confstr again with a bigger buffer. */
|
||||
for (size_t s;
|
||||
! (s = confstr (_CS_PATH, buf, bufsize)) || bufsize < s; )
|
||||
{
|
||||
if (buf != staticbuf)
|
||||
xfree (buf);
|
||||
if (!s)
|
||||
{
|
||||
staticbuf[0] = 1;
|
||||
buf = NULL;
|
||||
break;
|
||||
}
|
||||
buf = xmalloc (s);
|
||||
bufsize = s;
|
||||
}
|
||||
|
||||
if (s == 0)
|
||||
{
|
||||
staticbuf[0] = 1;
|
||||
buf = NULL;
|
||||
}
|
||||
|
||||
path = buf;
|
||||
|
||||
#elif defined DOS_NT
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue