From 40157ce2540282b1303d220a480429436d5ba407 Mon Sep 17 00:00:00 2001 From: Simon Reinhardt Date: Thu, 15 Oct 2015 19:35:29 +0100 Subject: [PATCH] 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. --- ChangeLog | 6 ++++++ lib/copy-file.c | 2 ++ 2 files changed, 8 insertions(+) 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; } -- 2.39.5