bug-coreutils
[Top][All Lists]
Advanced

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

[PATCH] sort.c: Fix minor memory leak, monthtab is never free'd if HAVE


From: Joey Degges
Subject: [PATCH] sort.c: Fix minor memory leak, monthtab is never free'd if HAVE_NL_LANGINFO is defined and we're not in the "C" locale
Date: Tue, 16 Feb 2010 01:26:16 -0800

Hello,

At sort.c:1137, in inittables(), monthtab[i].name is alloc'd
if HAVE_NL_LANGINFO is defined and we're not in the "C" locale.

This patch adds the function freetables() which frees monthtab[i].name if
the appropriate conditions are met. freetables() is called at the end of
main().

>From 75920d3d8e9632be1f7317d461b62ad14f3a12f0 Mon Sep 17 00:00:00 2001
From: Joey Degges <address@hidden>
Date: Mon, 15 Feb 2010 23:35:43 -0800
Subject: [PATCH 3/3] Fix minor memory leak: monthtab is never free'd if
HAVE_NL_LANGINFO is defined and we're not in the "C" locale.

---
 src/sort.c |   12 ++++++++++++
 1 files changed, 12 insertions(+), 0 deletions(-)

diff --git a/src/sort.c b/src/sort.c
index 94f5b64..48bc04d 100644
--- a/src/sort.c
+++ b/src/sort.c
@@ -1147,6 +1147,17 @@ inittables (void)
 #endif
 }

+static void
+freetables (void)
+{
+#if HAVE_NL_LANGINFO
+  size_t i;
+  if (hard_LC_TIME)
+    for (i = 0; i < MONTHS_PER_YEAR; i++)
+      free (monthtab[i].name);
+#endif
+}
+
 /* Specify how many inputs may be merged at once.
    This may be set on the command-line with the
    --batch-size option. */
@@ -3695,6 +3706,7 @@ main (int argc, char **argv)
   if (nfiles != 0)
     free (files);
   free (temp_dirs);
+  freetables ();

   if (have_read_stdin && fclose (stdin) == EOF)
     die (_("close failed"), "-");
-- 
1.6.6.1


reply via email to

[Prev in Thread] Current Thread [Next in Thread]