Plug default_PATH memory leak

* src/emacs.c (default_PATH): Fix very-unlikely memory leak.
This commit is contained in:
Paul Eggert 2026-05-19 22:17:40 -07:00
parent 1eb2e052bb
commit 59b2f8f1dc

View file

@ -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