From fb7579768d688a300c4ac76451e1fc7cad59e3e8 Mon Sep 17 00:00:00 2001
From: Paul Eggert <eggert@cs.ucla.edu>
Date: Mon, 31 Jan 2022 19:52:43 -0800
Subject: [PATCH] df: fix memory leak

* src/df.c (devlist_free): Remove.
(filter_mount_list): Free all of devlist, instead of merely
the entries in devlist_table.

Reference:https://github.com/coreutils/coreutils/commit/fb7579768d688a300c4ac76451e1fc7cad59e3e8
Conflict:NA

---
 src/df.c | 14 ++++----------
 1 file changed, 4 insertions(+), 10 deletions(-)

diff --git a/src/df.c b/src/df.c
index 7d3207807..4b2cfb77a 100644
--- a/src/df.c
+++ b/src/df.c
@@ -710,12 +710,6 @@ devlist_for_dev (dev_t dev)
   return found->seen_last;
 }
 
-static void
-devlist_free (void *p)
-{
-  free (p);
-}
-
 /* Filter mount list by skipping duplicate entries.
    In the case of duplicates - based on the device number - the mount entry
    with a '/' in its me_devname (i.e., not pseudo name like tmpfs) wins.
@@ -736,9 +730,7 @@ filter_mount_list (bool devices_only)
     mount_list_size++;
 
   devlist_table = hash_initialize (mount_list_size, NULL,
-                                 devlist_hash,
-                                 devlist_compare,
-                                 devlist_free);
+                                   devlist_hash, devlist_compare, NULL);
   if (devlist_table == NULL)
     xalloc_die ();
 
@@ -845,7 +837,9 @@ filter_mount_list (bool devices_only)
         me = device_list->me;
         me->me_next = mount_list;
         mount_list = me;
-        device_list = device_list->next;
+        struct devlist *next = device_list->next;
+        free (device_list);
+        device_list = next;
       }
 
       hash_free (devlist_table);
-- 
2.33.0

