summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2026-05-19 22:17:40 -0700
committerPaul Eggert <eggert@cs.ucla.edu>2026-05-23 19:18:52 -0700
commit59b2f8f1dc4513df32e81a7a0d38d5b09c0d6049 (patch)
tree48fcdabe50de6a0dbbc7cf8c306a5731a3a0336c
parent1eb2e052bb55184d62c1dec265f6d327be4e9113 (diff)
Plug default_PATH memory leak
* src/emacs.c (default_PATH): Fix very-unlikely memory leak.
-rw-r--r--src/emacs.c21
1 files changed, 12 insertions, 9 deletions
diff --git a/src/emacs.c b/src/emacs.c
index 11fe567737a..465a7a0b108 100644
--- a/src/emacs.c
+++ b/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