From 152be6db1b016ed2a510ddc3895a937b21fbd538 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Thu, 1 Apr 2021 00:59:54 -0700 Subject: [PATCH] xalloc: delay setting size until success MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit * lib/xalloc.h (x2nrealloc): Don’t change *PN until after xrealloc succeeds, in case xalloc_die or one of its callees or longjmp targets uses *PN. Similar code in xpalloc already does this. --- ChangeLog | 7 +++++++ lib/xalloc.h | 3 ++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 78bf3a5a74..784409dba9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2021-03-31 Paul Eggert + + xalloc: delay setting size until success + * lib/xalloc.h (x2nrealloc): Don’t change *PN until after xrealloc + succeeds, in case xalloc_die or one of its callees or longjmp + targets uses *PN. Similar code in xpalloc already does this. + 2021-03-28 Paul Eggert xalloc: new function xpalloc, from dfa diff --git a/lib/xalloc.h b/lib/xalloc.h index 76d83c63c1..5633fdf3c4 100644 --- a/lib/xalloc.h +++ b/lib/xalloc.h @@ -206,8 +206,9 @@ x2nrealloc (void *p, size_t *pn, size_t s) n += n / 2 + 1; } + p = xrealloc (p, n * s); *pn = n; - return xrealloc (p, n * s); + return p; } /* Return a pointer to a new buffer of N bytes. This is like xmalloc, -- 2.39.5