>From 22b911f63ca11395f03ce2ce3cc0b371a37a576d Mon Sep 17 00:00:00 2001 From: Bernhard Voelker Date: Thu, 18 Apr 2019 23:04:26 +0200 Subject: [PATCH] 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. --- ChangeLog | 8 ++++++++ lib/di-set.c | 3 ++- tests/test-di-set.c | 3 +++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 398c33968..916d154eb 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2019-04-18 Bernhard Voelker + + 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 * lib/str-two-way.h: Fix comment typo. diff --git a/lib/di-set.c b/lib/di-set.c index 2c0601e03..47ade5821 100644 --- a/lib/di-set.c +++ b/lib/di-set.c @@ -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); } diff --git a/tests/test-di-set.c b/tests/test-di-set.c index 6887be3b6..0f492c837 100644 --- a/tests/test-di-set.c +++ b/tests/test-di-set.c @@ -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 */ -- 2.21.0