]> Savannah Git Hosting - gnulib.git/commitdiff
copy-file: fix mem leak in error case
authorSimon Reinhardt <simon@keinstein.org>
Thu, 15 Oct 2015 18:35:29 +0000 (19:35 +0100)
committerPádraig Brady <P@draigBrady.com>
Thu, 15 Oct 2015 18:41:20 +0000 (19:41 +0100)
* lib/copy-file.c (qcopy_file_preserving): Free the 32KiB buffer
upon error opening or performing I/O to the src and dest files.

ChangeLog
lib/copy-file.c

index c9bc573cab7cda82a27eee286ee42aaed602af25..b02912d2f4bd784de9b046eacc3e2a98be8a5083 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2015-10-15  Simon Reinhardt  <simon@keinstein.org>
+
+       copy-file: fix mem leak in error case
+       * lib/copy-file.c (qcopy_file_preserving): Free the 32KiB buffer
+       upon error opening or performing I/O to the src and dest files.
+
 2015-10-15  Mike Frysinger  <vapier@chromium.org>
 
        localename: control langinfo.h inclusion
index da84c6cf2f191d69eb40868c97b925c66ef1cf92..90e377c300591daec8e581e681423d411834738b 100644 (file)
@@ -101,6 +101,7 @@ qcopy_file_preserving (const char *src_filename, const char *dest_filename)
     }
 
   free (buf);
+  buf = NULL; /* To avoid double free in error case.  */
 
 #if !USE_ACL
   if (close (dest_fd) < 0)
@@ -174,6 +175,7 @@ qcopy_file_preserving (const char *src_filename, const char *dest_filename)
  error_src:
   close (src_fd);
  error:
+  free (buf);
   return err;
 }