From 98d8f3d396b58d3086fd0416246908eba078917b Mon Sep 17 00:00:00 2001 From: NIIBE Yutaka Date: Wed, 28 May 2025 09:10:12 +0900 Subject: yat2m: Release the memory after the use. * doc/yat2m.c (add_content): Fix the type of LINE. (finish_page): Clean up. -- Signed-off-by: NIIBE Yutaka --- doc/yat2m.c | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/doc/yat2m.c b/doc/yat2m.c index a7f072e..ebb323c 100644 --- a/doc/yat2m.c +++ b/doc/yat2m.c @@ -940,7 +940,7 @@ roff_alternate (const char *line, const char *mode) /* Add the content of LINE to the section named SECTNAME. */ static void -add_content (const char *sectname, char *line, int verbatim) +add_content (const char *sectname, const char *line, int verbatim) { section_buffer_t sect; line_buffer_t lb; @@ -1937,7 +1937,24 @@ finish_page (void) fclose (fp); free (thepage.name); thepage.name = NULL; - /* FIXME: Cleanup the content. */ + + for (i=0; i < thepage.n_sections; i++) + { + line_buffer_t line, line_next; + + sect = thepage.sections + i; + for (line = sect->lines; line; line = line_next) + { + line_next = line->next; + free (line->line); + free (line); + } + + free (sect->name); + } + + free (thepage.sections); + thepage.n_sections = 0; } @@ -2227,7 +2244,6 @@ parse_file (const char *fname, FILE *fp, char **section_name, int in_pause) add_content (*section_name, line, 1); else if (got_line && thepage.name && *section_name && !in_pause) add_content (*section_name, line, 0); - } if (ferror (fp)) err ("%s:%d: read error: %s", fname, lnr, strerror (errno)); -- cgit v1.2.3