From e737c4b10ea1e228fdca13e91a012d412b2ae74e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20R=C3=BChsen?= Date: Mon, 16 Apr 2018 22:02:03 +0200 Subject: [PATCH] Fix 2 more memleaks * src/init.c (initialize): Use global var for wgetrc filename * src/iri.c (find_locale): Return strdup'ed locale string * src/options.h (struct options): Add wgetrcfile --- src/init.c | 18 ++++++++++-------- src/iri.c | 4 ++-- src/options.h | 1 + 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/init.c b/src/init.c index 4f5e646f..40275466 100644 --- a/src/init.c +++ b/src/init.c @@ -729,7 +729,7 @@ run_wgetrc (const char *file, file_stats_t *flstats) void initialize (void) { - char *file, *env_sysrc; + char *env_sysrc; file_stats_t flstats; bool ok = true; @@ -767,24 +767,24 @@ or specify a different file using --config.\n"), SYSTEM_WGETRC); } #endif /* Override it with your own, if one exists. */ - file = wgetrc_file_name (); - if (!file) + opt.wgetrcfile = wgetrc_file_name (); + if (!opt.wgetrcfile) return; /* #### We should canonicalize `file' and SYSTEM_WGETRC with something like realpath() before comparing them with `strcmp' */ #ifdef SYSTEM_WGETRC - if (!strcmp (file, SYSTEM_WGETRC)) + if (!strcmp (opt.wgetrcfile, SYSTEM_WGETRC)) { fprintf (stderr, _("\ %s: Warning: Both system and user wgetrc point to %s.\n"), - exec_name, quote (file)); + exec_name, quote (opt.wgetrcfile)); } else #endif - if (file_exists_p (file, &flstats)) - ok &= run_wgetrc (file, &flstats); + if (file_exists_p (opt.wgetrcfile, &flstats)) + ok &= run_wgetrc (opt.wgetrcfile, &flstats); - xfree (file); + xfree (opt.wgetrcfile); /* If there were errors processing either `.wgetrc', abort. */ if (!ok) @@ -2002,8 +2002,10 @@ cleanup (void) xfree (opt.retry_on_http_error); xfree (opt.encoding_remote); + xfree (opt.locale); xfree (opt.hsts_file); + xfree (opt.wgetrcfile); xfree (opt.homedir); xfree (exec_name); xfree (program_argstring); diff --git a/src/iri.c b/src/iri.c index ef51044b..7dcf3ac9 100644 --- a/src/iri.c +++ b/src/iri.c @@ -95,9 +95,9 @@ find_locale (void) const char *encoding = nl_langinfo(CODESET); if (!encoding || !*encoding) - return "ASCII"; + return xstrdup("ASCII"); - return encoding; + return xstrdup(encoding); } /* Basic check of an encoding name. */ diff --git a/src/options.h b/src/options.h index 4e6fe929..ce10dcaf 100644 --- a/src/options.h +++ b/src/options.h @@ -341,6 +341,7 @@ struct options #endif const char *homedir; /* the homedir of the running process */ + const char *wgetrcfile; /* the wgetrc file to be loaded */ }; extern struct options opt;