]> git.ipfire.org Git - thirdparty/gnulib.git/commitdiff
di-set: allow free with 'ino_map' being NULL
authorBernhard Voelker <mail@bernhard-voelker.de>
Thu, 18 Apr 2019 21:04:26 +0000 (23:04 +0200)
committerBernhard Voelker <mail@bernhard-voelker.de>
Thu, 18 Apr 2019 21:59:37 +0000 (23:59 +0200)
* lib/di-set.c (di_set_free): Avoid ino_map_free() when dis->ino_map
is NULL.  Bug introduced in commit 3703dbbe88dd.
* tests/test-di-set.c: Add di_set_free() right after di_set_alloc()
as a test.

ChangeLog
lib/di-set.c
tests/test-di-set.c

index 398c33968cd980dce471e6b42fd94bf02536754e..916d154ebee0351229c9eea53c10998f042797f5 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2019-04-18  Bernhard Voelker  <mail@bernhard-voelker.de>
+
+       di-set: allow free with 'ino_map' being NULL.
+       * lib/di-set.c (di_set_free): Avoid ino_map_free() when dis->ino_map
+       is NULL.  Bug introduced in commit 3703dbbe88dd.
+       * tests/test-di-set.c: Add di_set_free() right after di_set_alloc()
+       as a test.
+
 2019-04-14  Paul Eggert  <eggert@cs.ucla.edu>
 
        * lib/str-two-way.h: Fix comment typo.
index 2c0601e03b9fb09f3ada30110d4184d44738d7f8..47ade582190735035895e65e0e70c6ef4f3d20bf 100644 (file)
@@ -136,7 +136,8 @@ void
 di_set_free (struct di_set *dis)
 {
   hash_free (dis->dev_map);
-  ino_map_free (dis->ino_map);
+  if (dis->ino_map)
+    ino_map_free (dis->ino_map);
   free (dis->probe);
   free (dis);
 }
index 6887be3b611148dd2e9a440df3a54fb726cd176a..0f492c837fa90cd9545ce13582ae3480d5b22b45 100644 (file)
@@ -27,6 +27,9 @@ main (void)
 {
   struct di_set *dis = di_set_alloc ();
   ASSERT (dis);
+  di_set_free (dis); /* free with dis->ino_map still being NULL */
+  dis = di_set_alloc ();
+  ASSERT (dis);
 
   ASSERT (di_set_lookup (dis, 2, 5) == 0); /* initial lookup fails */
   ASSERT (di_set_insert (dis, 2, 5) == 1); /* first insertion succeeds */