From: Simon Reinhardt Date: Thu, 15 Oct 2015 18:35:29 +0000 (+0100) Subject: copy-file: fix mem leak in error case X-Git-Tag: v1.0~6927 X-Git-Url: https://gitweb.git.savannah.gnu.org/gitweb/?a=commitdiff_plain;h=40157ce2540282b1303d220a480429436d5ba407;p=gnulib.git 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. --- diff --git a/ChangeLog b/ChangeLog index c9bc573cab..b02912d2f4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2015-10-15 Simon Reinhardt + + 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 localename: control langinfo.h inclusion diff --git a/lib/copy-file.c b/lib/copy-file.c index da84c6cf2f..90e377c300 100644 --- a/lib/copy-file.c +++ b/lib/copy-file.c @@ -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; }