diff --git a/WHATS_NEW b/WHATS_NEW index dbb78d6ce..7508794bb 100644 --- a/WHATS_NEW +++ b/WHATS_NEW @@ -1,5 +1,6 @@ Version 2.02.128 - =================================== + Don't attempt to close config file that couldn't be opened. Check for valid cache mode in validation of cache segment. Change internal interface handling cache mode and policy. When no cache policy specified, prefer smq (if available) over mq. diff --git a/lib/config/config.c b/lib/config/config.c index cd6c1d808..ad2db76e3 100644 --- a/lib/config/config.c +++ b/lib/config/config.c @@ -582,8 +582,11 @@ int config_file_read(struct dm_config_tree *cft) if (!(cf->dev = dev_create_file(filename, NULL, NULL, 1))) return_0; - if (!dev_open_readonly_buffered(cf->dev)) + if (!dev_open_readonly_buffered(cf->dev)) { + dev_destroy_file(cf->dev); + cf->dev = NULL; return_0; + } } r = config_file_read_fd(cft, cf->dev, 0, (size_t) info.st_size, 0, 0, diff --git a/lib/device/dev-cache.c b/lib/device/dev-cache.c index e58ac0f5e..043a722e1 100644 --- a/lib/device/dev-cache.c +++ b/lib/device/dev-cache.c @@ -71,6 +71,16 @@ static void _dev_init(struct device *dev, int max_error_count) dm_list_init(&dev->open_list); } +void dev_destroy_file(struct device *dev) +{ + if (!(dev->flags & DEV_ALLOCED)) + return; + + dm_free((void *) dm_list_item(dev->aliases.n, struct dm_str_list)->str); + dm_free(dev->aliases.n); + dm_free(dev); +} + struct device *dev_create_file(const char *filename, struct device *dev, struct dm_str_list *alias, int use_malloc) { diff --git a/lib/device/dev-io.c b/lib/device/dev-io.c index d712f3154..8c2388bb0 100644 --- a/lib/device/dev-io.c +++ b/lib/device/dev-io.c @@ -586,12 +586,8 @@ static void _close(struct device *dev) log_debug_devs("Closed %s", dev_name(dev)); - if (dev->flags & DEV_ALLOCED) { - dm_free((void *) dm_list_item(dev->aliases.n, struct dm_str_list)-> - str); - dm_free(dev->aliases.n); - dm_free(dev); - } + if (dev->flags & DEV_ALLOCED) + dev_destroy_file(dev); } static int _dev_close(struct device *dev, int immediate) diff --git a/lib/device/device.h b/lib/device/device.h index dcc37137f..733b0d04e 100644 --- a/lib/device/device.h +++ b/lib/device/device.h @@ -123,6 +123,7 @@ void dev_flush(struct device *dev); struct device *dev_create_file(const char *filename, struct device *dev, struct dm_str_list *alias, int use_malloc); +void dev_destroy_file(struct device *dev); /* Return a valid device name from the alias list; NULL otherwise */ const char *dev_name_confirmed(struct device *dev, int quiet);