From 79f7afb125445d71faba47e3cb1a55102a9a07a3 Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Mon, 15 Apr 2019 07:37:55 +0200 Subject: [PATCH] diagnostics: fix memory leak in libtextstyle * src/complain.h, src/complain.c (complain_free): New. * src/main.c: Use it. --- src/complain.c | 6 ++++++ src/complain.h | 3 +++ src/main.c | 4 ++-- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/complain.c b/src/complain.c index b0daa4a9..97af2f95 100644 --- a/src/complain.c +++ b/src/complain.c @@ -278,6 +278,12 @@ complain_init (void) } } +void +complain_free (void) +{ + caret_free (); + styled_ostream_free (errstream); +} /* A diagnostic with FLAGS is about to be issued. With what severity? (severity_fatal, severity_error, severity_disabled, or diff --git a/src/complain.h b/src/complain.h index c136c071..199f388d 100644 --- a/src/complain.h +++ b/src/complain.h @@ -90,6 +90,9 @@ void warnings_argmatch (char *args); /** Initialize this module. */ void complain_init (void); +/** Reclaim resources. */ +void complain_free (void); + /** Initialize support for colored messages. */ void complain_init_color (void); diff --git a/src/main.c b/src/main.c index f0337b15..8b48ad27 100644 --- a/src/main.c +++ b/src/main.c @@ -234,8 +234,6 @@ main (int argc, char *argv[]) timevar_stop (tv_total); timevar_print (stderr); - caret_free (); - /* Fix input file now, even if there are errors: that's less warnings in the following runs. */ if (!fixits_empty ()) @@ -249,5 +247,7 @@ main (int argc, char *argv[]) } uniqstrs_free (); + complain_free (); + return complaint_status ? EXIT_FAILURE : EXIT_SUCCESS; }