From: Akim Demaille Date: Sun, 27 Jan 2019 17:49:36 +0000 (+0100) Subject: bitsetv: allow free on NULL. X-Git-Tag: v1.0~5104 X-Git-Url: https://gitweb.git.savannah.gnu.org/gitweb/?a=commitdiff_plain;h=954d1e36aa815994f7f5b1fcd46ebc96a63b8df4;p=gnulib.git bitsetv: allow free on NULL. * lib/bitsetv.c (bitsetv_free): Do nothing when the bitsetv is NULL. --- diff --git a/ChangeLog b/ChangeLog index 4e90bfd660..6134044422 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2019-01-27 Akim Demaille + + bitsetv: allow free on NULL. + * lib/bitsetv.c (bitsetv_free): Do nothing when the bitsetv is NULL. + 2019-01-27 Bruno Haible test-framework-sh: Improve maintainability. diff --git a/lib/bitsetv.c b/lib/bitsetv.c index e3cc5845a7..b7d0a01913 100644 --- a/lib/bitsetv.c +++ b/lib/bitsetv.c @@ -71,9 +71,12 @@ bitsetv_create (bitset_bindex n_vecs, bitset_bindex n_bits, unsigned attr) void bitsetv_free (bitsetv bsetv) { - for (bitset_bindex i = 0; bsetv[i]; i++) - BITSET_FREE_ (bsetv[i]); - free (bsetv); + if (bsetv) + { + for (bitset_bindex i = 0; bsetv[i]; i++) + BITSET_FREE_ (bsetv[i]); + free (bsetv); + } } diff --git a/lib/bitsetv.h b/lib/bitsetv.h index 798b70d9b4..0971d7adc9 100644 --- a/lib/bitsetv.h +++ b/lib/bitsetv.h @@ -33,7 +33,7 @@ bitsetv bitsetv_alloc (bitset_bindex, bitset_bindex, enum bitset_type); attribute hints specified by ATTR. */ bitsetv bitsetv_create (bitset_bindex, bitset_bindex, unsigned); -/* Free vector of bitsets. */ +/* Free vector of bitsets. Do nothing if NULL. */ void bitsetv_free (bitsetv); /* Zero vector of bitsets. */