[PATCH] Fix memleak and the implementation of remove_file in builtin-rm.c

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Actually, just replace it with the one from builtin-merge-recursive.c,
except for ignoring ENOENT error.

Signed-off-by: Alex Riesen <raa.lkml@xxxxxxxxx>
---

It is the same as in merge-recursive, but they're so small so unless
we get a special file with such random routines there is no much point
exporting it. Actually, we do seem to have such a file: dir.c. It is
already plagued by file_exists kind of things, why not remove_path...

 builtin-rm.c |   24 ++++++++++--------------
 1 files changed, 10 insertions(+), 14 deletions(-)

diff --git a/builtin-rm.c b/builtin-rm.c
index fdac34f..910a34d 100644
--- a/builtin-rm.c
+++ b/builtin-rm.c
@@ -31,22 +31,18 @@ static void add_list(const char *name)
 
 static int remove_file(const char *name)
 {
-	int ret;
-	char *slash;
-
-	ret = unlink(name);
-	if (ret && errno == ENOENT)
-		/* The user has removed it from the filesystem by hand */
-		ret = errno = 0;
-
-	if (!ret && (slash = strrchr(name, '/'))) {
-		char *n = xstrdup(name);
-		do {
-			n[slash - name] = 0;
-			name = n;
-		} while (!rmdir(name) && (slash = strrchr(name, '/')));
+	char *slash, *dirs;
+
+	if (unlink(name) && errno != ENOENT)
+		return -1;
+	dirs = xstrdup(name);
+	while ((slash = strrchr(name, '/'))) {
+		*slash = '\0';
+		if (rmdir(name) != 0)
+			break;
 	}
-	return ret;
+	free(dirs);
+	return 0;
 }
 
 static int check_local_mod(unsigned char *head, int index_only)
-- 
1.6.0.2.328.g14651

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux