diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2013-04-22 23:12:15 -0400 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2013-04-24 00:25:04 -0400 |
commit | ef42202ac8ed27e7ff1fc90ef8bc2590046dff25 (patch) | |
tree | b1646eeb8ef5070337ae701ffb4abf0e398640ad /src/locale | |
parent | c79bb9e4e2e5b96b2ae2c432bf8b0ff9674fce60 (diff) |
Add set_consume which always takes ownership
Freeing in error path is the common pattern with set_put().
Diffstat (limited to 'src/locale')
-rw-r--r-- | src/locale/localectl.c | 22 |
1 files changed, 7 insertions, 15 deletions
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; } |