summaryrefslogtreecommitdiff
path: root/src/doc.c
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2016-12-08 10:43:11 -0800
committerPaul Eggert <eggert@cs.ucla.edu>2016-12-08 10:43:58 -0800
commit162ba405ac144c2a0cb6854f791ff7d3203b0e2f (patch)
treed0980d15280591b5d8a4dc5d72cda7e55fbfe05d /src/doc.c
parentc685e4c92909b2ae0140953417e0d856eb34ba33 (diff)
downloademacs-162ba405ac144c2a0cb6854f791ff7d3203b0e2f.tar.gz
Fix unlikely substitute-command-keys memory leak
* src/doc.c (Fsubstitute_command_keys): Free buffer when unwinding.
Diffstat (limited to 'src/doc.c')
-rw-r--r--src/doc.c17
1 files changed, 13 insertions, 4 deletions
diff --git a/src/doc.c b/src/doc.c
index ce4f89b94dd..6a78ed657c1 100644
--- a/src/doc.c
+++ b/src/doc.c
@@ -772,6 +772,8 @@ Otherwise, return a new string. */)
/* Extra room for expansion due to replacing ‘\[]’ with ‘M-x ’. */
enum { EXTRA_ROOM = sizeof "M-x " - sizeof "\\[]" };
+ ptrdiff_t count = SPECPDL_INDEX ();
+
if (bsize <= sizeof sbuf - EXTRA_ROOM)
{
abuf = NULL;
@@ -779,7 +781,10 @@ Otherwise, return a new string. */)
bsize = sizeof sbuf;
}
else
- buf = abuf = xpalloc (NULL, &bsize, EXTRA_ROOM, STRING_BYTES_BOUND, 1);
+ {
+ buf = abuf = xpalloc (NULL, &bsize, EXTRA_ROOM, STRING_BYTES_BOUND, 1);
+ record_unwind_protect_ptr (xfree, abuf);
+ }
bufp = buf;
strp = SDATA (str);
@@ -929,7 +934,12 @@ Otherwise, return a new string. */)
abuf = xpalloc (abuf, &bsize, need - avail,
STRING_BYTES_BOUND, 1);
if (buf == sbuf)
- memcpy (abuf, sbuf, offset);
+ {
+ record_unwind_protect_ptr (xfree, abuf);
+ memcpy (abuf, sbuf, offset);
+ }
+ else
+ set_unwind_protect_ptr (count, xfree, abuf);
buf = abuf;
bufp = buf + offset;
}
@@ -988,8 +998,7 @@ Otherwise, return a new string. */)
}
else
tem = string;
- xfree (abuf);
- return tem;
+ return unbind_to (count, tem);
}
void