diff options
| author | Paul Eggert <eggert@cs.ucla.edu> | 2021-03-24 14:12:22 -0700 |
|---|---|---|
| committer | Paul Eggert <eggert@cs.ucla.edu> | 2021-03-24 14:12:48 -0700 |
| commit | 1399b225ebecdbac80cc14be87c2454311f3b40f (patch) | |
| tree | 66aa5a023ec6422790f4c52a0320d09ccab0f8d8 /src | |
| parent | b48581daa81ca21437f8154721887f76e1c4c34d (diff) | |
| download | diffutils-1399b225ebecdbac80cc14be87c2454311f3b40f.tar.gz | |
diff: plug memory leak in ifdef.c
Problem reported by Than (Bug#47362).
Fix the bug by using xmalloca instead of vararrays.
* bootstrap.conf (gnulib_modules): Add xmalloca; remove vararrays.
* configure.ac: Remove AC_C_VARARRAYS.
* src/ifdef.c: Include xmalloca.h instead of xalloc.h.
(do_printf_spec): Use xmalloca instead of an xmalloc
that lacks a corresponding ‘free’ if HAVE_C_VARARRAYS
due to a typo in 2017-05-18T05:51:31Z!meyering@fb.com.
Diffstat (limited to 'src')
| -rw-r--r-- | src/ifdef.c | 12 |
1 files changed, 3 insertions, 9 deletions
diff --git a/src/ifdef.c b/src/ifdef.c index 8e64b4c..d40a88e 100644 --- a/src/ifdef.c +++ b/src/ifdef.c @@ -22,7 +22,7 @@ #include "diff.h" -#include <xalloc.h> +#include <xmalloca.h> struct group { @@ -362,20 +362,14 @@ do_printf_spec (FILE *out, char const *spec, printint print_value = value; size_t spec_prefix_len = f - spec - 2; size_t pI_len = sizeof pI - 1; -#if 0 - char format[spec_prefix_len + pI_len + 2]; -#else - char *format = xmalloc (spec_prefix_len + pI_len + 2); -#endif + char *format = xmalloca (spec_prefix_len + pI_len + 2); char *p = format + spec_prefix_len + pI_len; memcpy (format, spec, spec_prefix_len); memcpy (format + spec_prefix_len, pI, pI_len); *p++ = c; *p = '\0'; fprintf (out, format, print_value); -#if ! HAVE_C_VARARRAYS - free (format); -#endif + freea (format); } } break; |
