coreutils
[Top][All Lists]
Advanced

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

Re: [PATCH] maint: fix a memory leak in df


From: Bernhard Voelker
Subject: Re: [PATCH] maint: fix a memory leak in df
Date: Fri, 12 Jul 2013 12:30:15 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130329 Thunderbird/17.0.5

On 07/11/2013 02:53 PM, Pádraig Brady wrote:
> Attached.  Note it's updated to free _all_ discarded mount items,
> not just those being replaced.

Hi Padraig,

sorry to be late.
What do you think about the following patch to give the
discard_me variable a better scope?

Have a nice day,
Berny


>From 725528ae69f2c0149b1d60225104fdb92baad29d Mon Sep 17 00:00:00 2001
From: Bernhard Voelker <address@hidden>
Date: Fri, 12 Jul 2013 12:22:46 +0200
Subject: [PATCH] maint: give variable a better scope in df.c

* src/df.c (filter_mount_list): Move definition of discard_me down
where it is used.
---
 src/df.c | 30 ++++++++++++------------------
 1 file changed, 12 insertions(+), 18 deletions(-)

diff --git a/src/df.c b/src/df.c
index e018064..172e645 100644
--- a/src/df.c
+++ b/src/df.c
@@ -617,7 +617,6 @@ filter_mount_list (void)
     {
       struct stat buf;
       struct devlist *devlist;
-      struct mount_entry *discard_me = NULL;

       if (-1 == stat (me->me_mountdir, &buf))
         {
@@ -636,7 +635,7 @@ filter_mount_list (void)

               if (devlist)
                 {
-                  discard_me = me;
+                  struct mount_entry *discard_me = me;

                   /* Let the shorter mountdir win.  */
                   if (! strchr (devlist->me->me_devname, '/')
@@ -646,26 +645,21 @@ filter_mount_list (void)
                       discard_me = devlist->me;
                       devlist->me = me;
                     }
+                  me = me->me_next;
+                  free_mount_entry (discard_me);
+                  continue;
                 }
             }
         }

-      if (discard_me)
-        {
-           me = me->me_next;
-           free_mount_entry (discard_me);
-        }
-      else
-        {
-          /* Add the device number to the global list devlist.  */
-          devlist = xmalloc (sizeof *devlist);
-          devlist->me = me;
-          devlist->dev_num = buf.st_dev;
-          devlist->next = devlist_head;
-          devlist_head = devlist;
-
-          me = me->me_next;
-        }
+      /* Add the device number to the global list devlist.  */
+      devlist = xmalloc (sizeof *devlist);
+      devlist->me = me;
+      devlist->dev_num = buf.st_dev;
+      devlist->next = devlist_head;
+      devlist_head = devlist;
+
+      me = me->me_next;
     }

   /* Finally rebuild the mount_list from the devlist.  */
-- 
1.8.3.1




reply via email to

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