summary refs log tree commit diff
diff options
context:
space:
mode:
authorLeah Neukirchen <leah@vuxu.org>2017-11-08 13:22:02 +0100
committerLeah Neukirchen <leah@vuxu.org>2017-11-08 13:22:02 +0100
commite15895fba53c0127c64db978386236f756364e95 (patch)
treecaf894da50417a620d179632fb9c6f8f9282c0f8
parent28b38582ef08067baed321bf76de2c0ea82db466 (diff)
downloadlr-e15895fba53c0127c64db978386236f756364e95.tar.gz
lr-e15895fba53c0127c64db978386236f756364e95.tar.xz
lr-e15895fba53c0127c64db978386236f756364e95.zip
free fileinfo when -U is used
-rw-r--r--lr.c18
1 files changed, 15 insertions, 3 deletions
diff --git a/lr.c b/lr.c
index 181fb82..258e910 100644
--- a/lr.c
+++ b/lr.c
@@ -1837,6 +1837,14 @@ print(const void *nodep, const VISIT which, const int depth)
 		print_format(*(struct fileinfo **)nodep);
 }
 
+void
+free_fi(struct fileinfo *fi)
+{
+	if (fi)
+		free(fi->fpath);
+	free(fi);
+}
+
 int
 callback(const char *fpath, const struct stat *sb, int depth, ino_t entries, off_t total)
 {
@@ -1849,8 +1857,10 @@ callback(const char *fpath, const struct stat *sb, int depth, ino_t entries, off
 	fi->color = current_color;
 	memcpy((char *)&fi->sb, (char *)sb, sizeof (struct stat));
 
-	if (expr && !eval(expr, fi))
+	if (expr && !eval(expr, fi)) {
+		free_fi(fi);
 		return 0;
+	}
 
 	if (need_xattr) {
 		strncpy(fi->xattr, xattr_string(fi->fpath), sizeof fi->xattr);
@@ -1859,11 +1869,13 @@ callback(const char *fpath, const struct stat *sb, int depth, ino_t entries, off
 	} else
 		memset(fi->xattr, 0, sizeof fi->xattr);
 
-	if (Uflag)
+	if (Uflag) {
 		print(&fi, postorder, depth);
-	else
+		free_fi(fi);
+	} else {
 		// add to the tree, note that this will elimnate duplicate files
 		tsearch(fi, &root, order);
+	}
 
 	if (depth > maxdepth)
 		maxdepth = depth;