aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--coreutils/cp.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/coreutils/cp.c b/coreutils/cp.c
index 2c0b90bc9..9f6c12367 100644
--- a/coreutils/cp.c
+++ b/coreutils/cp.c
@@ -182,10 +182,12 @@ int cp_main(int argc, char **argv)
if (copy_file(*argv, dest, flags) < 0) {
status = EXIT_FAILURE;
}
- free((void*)dest);
if (*++argv == last) {
+ /* possibly leaking dest... */
break;
}
+ /* don't move up: dest may be == last and not malloced! */
+ free((void*)dest);
}
/* Exit. We are NOEXEC, not NOFORK. We do exit at the end of main() */