]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
locale-util: fix memleak on failure
authorYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 14 Jun 2022 00:04:00 +0000 (09:04 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 14 Jun 2022 11:56:23 +0000 (20:56 +0900)
src/basic/locale-util.c

index cb99641263b0a53f06bc6bca887b29f11eb0c138..3fce1a55f6126b870165610c9bbd188cbf526b1b 100644 (file)
@@ -160,7 +160,7 @@ static int add_locales_from_archive(Set *locales) {
         return r;
 }
 
-static int add_locales_from_libdir (Set *locales) {
+static int add_locales_from_libdir(Set *locales) {
         _cleanup_closedir_ DIR *dir = NULL;
         int r;
 
@@ -187,7 +187,7 @@ static int add_locales_from_libdir (Set *locales) {
 }
 
 int get_locales(char ***ret) {
-        _cleanup_set_free_ Set *locales = NULL;
+        _cleanup_set_free_free_ Set *locales = NULL;
         _cleanup_strv_free_ char **l = NULL;
         int r;
 
@@ -207,6 +207,9 @@ int get_locales(char ***ret) {
         if (!l)
                 return -ENOMEM;
 
+        /* Now, all elements are owned by strv 'l'. Hence, do not call set_free_free(). */
+        locales = set_free(locales);
+
         r = getenv_bool("SYSTEMD_LIST_NON_UTF8_LOCALES");
         if (r == -ENXIO || r == 0) {
                 char **a, **b;