From ef42202ac8ed27e7ff1fc90ef8bc2590046dff25 Mon Sep 17 00:00:00 2001 From: Zbigniew Jędrzejewski-Szmek Date: Mon, 22 Apr 2013 23:12:15 -0400 Subject: Add set_consume which always takes ownership Freeing in error path is the common pattern with set_put(). --- src/locale/localectl.c | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) (limited to 'src/locale') diff --git a/src/locale/localectl.c b/src/locale/localectl.c index ea9187ff84..50250c4b47 100644 --- a/src/locale/localectl.c +++ b/src/locale/localectl.c @@ -369,9 +369,8 @@ static int add_locales_from_archive(Set *locales) { goto finish; } - r = set_put(locales, z); + r = set_consume(locales, z); if (r < 0) { - free(z); log_error("Failed to add locale: %s", strerror(-r)); goto finish; } @@ -411,14 +410,10 @@ static int add_locales_from_libdir (Set *locales) { if (!z) return log_oom(); - r = set_put(locales, z); - if (r < 0) { - free(z); - - if (r != -EEXIST) { - log_error("Failed to add locale: %s", strerror(-r)); - return r; - } + r = set_consume(locales, z); + if (r < 0 && r != -EEXIST) { + log_error("Failed to add locale: %s", strerror(-r)); + return r; } errno = 0; @@ -526,12 +521,9 @@ static int nftw_cb( if (e) *e = 0; - r = set_put(keymaps, p); - if (r == -EEXIST) - free(p); - else if (r < 0) { + r = set_consume(keymaps, p); + if (r < 0 && r != -EEXIST) { log_error("Can't add keymap: %s", strerror(-r)); - free(p); return r; } -- cgit v1.2.3-54-g00ecf