[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH] split: plug a nominal leak
From: |
Jim Meyering |
Subject: |
Re: [PATCH] split: plug a nominal leak |
Date: |
Sat, 04 Aug 2012 11:12:29 +0200 |
Pádraig Brady wrote:
> On 08/03/2012 01:53 PM, Jim Meyering wrote:
>> I ran "make check" on valgrind-wrapped tools (took most of a day on a
>> 6/12-core system) and saw split at the top of the list of "definitely lost
>> buffer" leaks. So far, the only ones I've investigated are not important,
>> but at least now, they are plugged and will not distract us further:
>
> Yes, these are only wasted cycles before exit().
> I'd suggest wrapping in IF_LINT ();
> as we do in df.c and sort.c
Good point. Thanks for the reminder.
I've also combined those two into a single commit:
>From e85aab8c33abcfe32bf46fa97c214baa9a60b7cd Mon Sep 17 00:00:00 2001
From: Jim Meyering <address@hidden>
Date: Thu, 2 Aug 2012 19:31:36 +0200
Subject: [PATCH] split: plug nominal leaks
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
* src/split.c (lines_rr) [IF_LINT]: Plug a harmless leak.
(main) [IF_LINT]: Free a usually-small (~70KB) buffer
just before exit, mainly to take this off the radar of
leak-detecting tools.
Improved-by: Pádraig Brady.
---
src/split.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/src/split.c b/src/split.c
index 7ba743c..d1037ec 100644
--- a/src/split.c
+++ b/src/split.c
@@ -1044,6 +1044,7 @@ no_filters:
files[i_file].ofd = OFD_APPEND;
}
}
+ IF_LINT (free (files));
}
#define FAIL_ONLY_ONE_WAY() \
@@ -1075,7 +1076,6 @@ main (int argc, char **argv)
{
enum Split_type split_type = type_undef;
size_t in_blk_size = 0; /* optimal block size of input file device */
- char *buf; /* file i/o buffer */
size_t page_size = getpagesize ();
uintmax_t k_units = 0;
uintmax_t n_units;
@@ -1382,7 +1382,8 @@ main (int argc, char **argv)
file_size = MAX (file_size, n_units);
}
- buf = ptr_align (xmalloc (in_blk_size + 1 + page_size - 1), page_size);
+ void *b = xmalloc (in_blk_size + 1 + page_size - 1);
+ char *buf = ptr_align (b, page_size);
/* When filtering, closure of one pipe must not terminate the process,
as there may still be other streams expecting input from us. */
@@ -1432,6 +1433,8 @@ main (int argc, char **argv)
abort ();
}
+ IF_LINT (free (b));
+
if (close (STDIN_FILENO) != 0)
error (EXIT_FAILURE, errno, "%s", infile);
closeout (NULL, output_desc, filter_pid, outfile);
--
1.7.12.rc1.10.g97c7934