chiark / gitweb /
Add set_consume which always takes ownership
[elogind.git] / src / locale / localectl.c
index eb94d13ad5b7104c2306e314ea36d9409ec38720..50250c4b476df5576713c1253aadd1a090a2f7a6 100644 (file)
@@ -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;
                 }
@@ -387,7 +386,7 @@ static int add_locales_from_archive(Set *locales) {
 }
 
 static int add_locales_from_libdir (Set *locales) {
-        DIR _cleanup_closedir_ *dir;
+        _cleanup_closedir_ DIR *dir;
         struct dirent *entry;
         int r;
 
@@ -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;
         }
 
@@ -539,7 +531,7 @@ static int nftw_cb(
 }
 
 static int list_vconsole_keymaps(DBusConnection *bus, char **args, unsigned n) {
-        char _cleanup_strv_free_ **l = NULL;
+        _cleanup_strv_free_ char **l = NULL;
 
         keymaps = set_new(string_hash_func, string_compare_func);
         if (!keymaps)
@@ -611,7 +603,7 @@ static int set_x11_keymap(DBusConnection *bus, char **args, unsigned n) {
 
 static int list_x11_keymaps(DBusConnection *bus, char **args, unsigned n) {
         _cleanup_fclose_ FILE *f = NULL;
-        char _cleanup_strv_free_ **list = NULL;
+        _cleanup_strv_free_ char **list = NULL;
         char line[LINE_MAX];
         enum {
                 NONE,