From 5b6accf9d94d507491925783053fec79d29d7f55 Mon Sep 17 00:00:00 2001 From: bde Date: Sat, 8 Nov 2003 09:55:16 +0000 Subject: 1. Fixed leakage of a file descriptor for every non-fatal failure in rm_overwrite() (for rm -P). 2. Print the file name in the error message for (fatal) malloc() failures in rm_overwrite(). I first thought that malloc() failures should be non-fatal since they don't prevent proceeding the the next file, but making them non-fatal would normally give too much output for rm -Pr on a large tree in the unlikely event that even one occurs, since the malloc()ed amounts are usually the same. Just print the file name since the malloc()ed amounts are not always the same and it doesn't hurt to know where rm was when it quit. Submitted by: guido ((1) and original version of (2)) --- bin/rm/rm.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/bin/rm/rm.c b/bin/rm/rm.c index ea65d3b..7f8f230 100644 --- a/bin/rm/rm.c +++ b/bin/rm/rm.c @@ -384,7 +384,7 @@ rm_overwrite(char *file, struct stat *sbp) goto err; bsize = MAX(fsb.f_iosize, 1024); if ((buf = malloc(bsize)) == NULL) - err(1, "malloc"); + err(1, "%s: malloc", file); #define PASS(byte) { \ memset(buf, byte, bsize); \ @@ -409,6 +409,8 @@ rm_overwrite(char *file, struct stat *sbp) err: eval = 1; if (buf) free(buf); + if (fd != -1) + close(fd); warn("%s", file); } -- cgit v1.1