From: Bruno Haible Date: Tue, 23 Mar 2021 00:19:06 +0000 (+0100) Subject: clean-temp-simple: Fix a rare memory leak. X-Git-Tag: v1.0~3005 X-Git-Url: https://gitweb.git.savannah.gnu.org/gitweb/?a=commitdiff_plain;h=79a63f591a3e27be1c0ef540dd8dd3ac811d3ff8;p=gnulib.git clean-temp-simple: Fix a rare memory leak. * lib/clean-temp-simple.c (register_temporary_file): Fix cleanup code. --- diff --git a/ChangeLog b/ChangeLog index 6640b80297..b2004479a2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2021-03-22 Bruno Haible + + clean-temp-simple: Fix a rare memory leak. + * lib/clean-temp-simple.c (register_temporary_file): Fix cleanup code. + 2021-03-22 Bruno Haible clean-temp-simple: Relicense under LGPLv2+. diff --git a/lib/clean-temp-simple.c b/lib/clean-temp-simple.c index ae8b3bbc98..42b2c0d883 100644 --- a/lib/clean-temp-simple.c +++ b/lib/clean-temp-simple.c @@ -339,15 +339,16 @@ register_temporary_file (const char *absolute_file_name) /* Add absolute_file_name to file_cleanup_list, without duplicates. */ if (gl_list_search (file_cleanup_list, absolute_file_name) == NULL) { - absolute_file_name = strdup (absolute_file_name); - if (absolute_file_name == NULL) + char *absolute_file_name_copy = strdup (absolute_file_name); + if (absolute_file_name_copy == NULL) { ret = -1; goto done; } - if (gl_list_nx_add_first (file_cleanup_list, absolute_file_name) + if (gl_list_nx_add_first (file_cleanup_list, absolute_file_name_copy) == NULL) { + free (absolute_file_name_copy); ret = -1; goto done; }