diff options
author | Jim Meyering <jim@meyering.net> | 1996-12-30 05:43:58 +0000 |
---|---|---|
committer | Jim Meyering <jim@meyering.net> | 1996-12-30 05:43:58 +0000 |
commit | 1ba3bd3896cffd70c1860f6d5cead8dc6899c7f9 (patch) | |
tree | e103e011b3795e1516feeae6e0c527e12e130e84 | |
parent | fb59a28b16c262649a5e2a8612d7bce54f917b8a (diff) | |
download | coreutils-1ba3bd3896cffd70c1860f6d5cead8dc6899c7f9.tar.xz |
(init_header): Plug a small memory leak by using stack
rather than heap for a 15-byte temporary buffer.
-rw-r--r-- | src/pr.c | 16 |
1 files changed, 7 insertions, 9 deletions
@@ -1360,7 +1360,7 @@ init_header (char *filename, int desc) int chars_per_middle, chars_free, lhs_blanks, rhs_blanks; char *f = filename; char *no_middle = ""; - char *header_text, *t_buf; + char *header_text; struct tm *tmptr; struct stat st; char *datim = "- Date/Time --"; @@ -1376,18 +1376,16 @@ init_header (char *filename, int desc) sprintf (header, "%s", " "); /* blank line header */ else { +#define T_BUF_FMT "%y-%m-%d %H:%M" /* date/time short format */ +#define T_BUF_SIZE 15 + char t_buf[T_BUF_SIZE]; + /* If parallel files or standard input, use current time. */ if (desc < 0 || !strcmp (filename, "-") || fstat (desc, &st)) st.st_mtime = time (NULL); - { - size_t t_buf_size = 15; - const char *fmt = "%y-%m-%d %H:%M"; /* date/time short format */ - - t_buf = (char *) xmalloc (t_buf_size); - tmptr = localtime (&st.st_mtime); - strftime (t_buf, t_buf_size, fmt, tmptr); - } + tmptr = localtime (&st.st_mtime); + strftime (t_buf, T_BUF_SIZE, T_BUF_FMT, tmptr); chars_per_middle = chars_per_line - CHARS_FOR_DATE_AND_PAGE; if (chars_per_middle < 3) |