[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
FYI: plug some small or inconsequential leaks
From: |
Jim Meyering |
Subject: |
FYI: plug some small or inconsequential leaks |
Date: |
Thu, 16 Nov 2006 09:27:03 +0100 |
I'm eliminating leaks found by running valgrind:
Help valgrind see that there is no leak in dd.c.
* src/dd.c (dd_copy): Declare real_buf and real_obuf to be static,
so we need not free them at all. This is easier than freeing
both buffers at each of the early "return"s.
* src/csplit.c (load_buffer): Plug an inconsequential leak.
diff --git a/src/dd.c b/src/dd.c
index dc71a03..f1dc474 100644
--- a/src/dd.c
+++ b/src/dd.c
@@ -1377,8 +1377,10 @@ static int
dd_copy (void)
{
char *ibuf, *bufstart; /* Input buffer. */
- char *real_buf; /* real buffer address before alignment */
- char *real_obuf;
+ /* These are declared static so that even though we don't free the
+ buffers, valgrind will recognize that there is no "real" leak. */
+ static char *real_buf; /* real buffer address before alignment */
+ static char *real_obuf;
ssize_t nread; /* Bytes read in the current block. */
/* If nonzero, then the previously read block was partial and
@@ -1598,9 +1600,6 @@ dd_copy (void)
}
}
- free (real_buf);
- free (real_obuf);
-
if ((conversions_mask & C_FDATASYNC) && fdatasync (STDOUT_FILENO) != 0)
{
if (errno != ENOSYS && errno != EINVAL)
diff --git a/src/csplit.c b/src/csplit.c
index e174ee5..382fd66 100644
--- a/src/csplit.c
+++ b/src/csplit.c
@@ -526,6 +526,8 @@ load_buffer (void)
if (lines_found)
save_buffer (b);
+ else
+ free (b);
return lines_found != 0;
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- FYI: plug some small or inconsequential leaks,
Jim Meyering <=