From 3c1725e7a1805c8c99f021a04f03bf5a783ffecf Mon Sep 17 00:00:00 2001 From: Steven Schubiger Date: Wed, 12 Nov 2008 12:02:37 +0100 Subject: [PATCH] Return some memory control back to format_and_print_line. --- src/ChangeLog | 5 +++++ src/main.c | 22 ++++++++++------------ 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index 3c023d66..27f29874 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,8 @@ +2008-11-12 Steven Schubiger + + * main.c (print_version): Hand the relevant + xstrdup/xfree calls back to format_and_print_line(). + 2008-11-11 Steven Schubiger * main.c (format_and_print_line): Move both the memory diff --git a/src/main.c b/src/main.c index d4fea4f3..b0fceae0 100644 --- a/src/main.c +++ b/src/main.c @@ -706,16 +706,18 @@ prompt_for_password (void) and an appropriate number of spaces are added on subsequent lines.*/ static void -format_and_print_line (const char *prefix, char *line, +format_and_print_line (const char *prefix, const char *line, int line_length) { int leading_spaces; int remaining_chars; - char *token; + char *line_dup, *token; assert (prefix != NULL); assert (line != NULL); + line_dup = xstrdup (line); + if (line_length <= 0) line_length = max_chars_per_line; @@ -723,7 +725,7 @@ format_and_print_line (const char *prefix, char *line, printf ("%s", prefix); remaining_chars = line_length - leading_spaces; /* We break on spaces. */ - token = strtok (line, " "); + token = strtok (line_dup, " "); while (token != NULL) { /* If however a token is much larger than the maximum @@ -746,6 +748,8 @@ format_and_print_line (const char *prefix, char *line, } printf ("\n"); + + xfree (line_dup); } static void @@ -803,23 +807,17 @@ print_version (void) putchar ('\n'); #endif - line = xstrdup (LOCALEDIR); format_and_print_line (locale_title, - line, + LOCALEDIR, max_chars_per_line); - xfree (line); - line = xstrdup (compilation_string); format_and_print_line (compile_title, - line, + compilation_string, max_chars_per_line); - xfree (line); - line = xstrdup (link_string); format_and_print_line (link_title, - line, + link_string, max_chars_per_line); - xfree (line); printf ("\n"); /* TRANSLATORS: When available, an actual copyright character -- 2.39.2