]> Savannah Git Hosting - gnulib.git/commitdiff
clean-temp-simple: Fix a rare memory leak.
authorBruno Haible <bruno@clisp.org>
Tue, 23 Mar 2021 00:19:06 +0000 (01:19 +0100)
committerBruno Haible <bruno@clisp.org>
Tue, 23 Mar 2021 00:19:06 +0000 (01:19 +0100)
* lib/clean-temp-simple.c (register_temporary_file): Fix cleanup code.

ChangeLog
lib/clean-temp-simple.c

index 6640b80297f5dabb40ae357c2142b76c84216308..b2004479a23a582fedc1b4f3114e2b5a9759a8d9 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2021-03-22  Bruno Haible  <bruno@clisp.org>
+
+       clean-temp-simple: Fix a rare memory leak.
+       * lib/clean-temp-simple.c (register_temporary_file): Fix cleanup code.
+
 2021-03-22  Bruno Haible  <bruno@clisp.org>
 
        clean-temp-simple: Relicense under LGPLv2+.
index ae8b3bbc98972193f367278b171a801dac85c054..42b2c0d883e262339056c7e30cc61a29ff8b0e19 100644 (file)
@@ -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;
         }