teknoraver / rpms / systemd

Forked from rpms/systemd 3 months ago
Clone

Blame SOURCES/0215-locale-util-fix-memleak-on-failure.patch

8d419f
From 97c96647418ffbadf3d964d76a5f54a9c54535c1 Mon Sep 17 00:00:00 2001
8d419f
From: Yu Watanabe <watanabe.yu+github@gmail.com>
8d419f
Date: Tue, 14 Jun 2022 09:04:00 +0900
8d419f
Subject: [PATCH] locale-util: fix memleak on failure
8d419f
8d419f
(cherry picked from commit 065058e63b566e21af737150ecd12bff57b97124)
8d419f
8d419f
Related: #2087652
8d419f
---
8d419f
 src/basic/locale-util.c | 7 +++++--
8d419f
 1 file changed, 5 insertions(+), 2 deletions(-)
8d419f
8d419f
diff --git a/src/basic/locale-util.c b/src/basic/locale-util.c
8d419f
index 7f1a2f15f7..abbebc7666 100644
8d419f
--- a/src/basic/locale-util.c
8d419f
+++ b/src/basic/locale-util.c
8d419f
@@ -156,7 +156,7 @@ static int add_locales_from_archive(Set *locales) {
8d419f
         return r;
8d419f
 }
8d419f
 
8d419f
-static int add_locales_from_libdir (Set *locales) {
8d419f
+static int add_locales_from_libdir(Set *locales) {
8d419f
         _cleanup_closedir_ DIR *dir = NULL;
8d419f
         int r;
8d419f
 
8d419f
@@ -183,7 +183,7 @@ static int add_locales_from_libdir (Set *locales) {
8d419f
 }
8d419f
 
8d419f
 int get_locales(char ***ret) {
8d419f
-        _cleanup_set_free_ Set *locales = NULL;
8d419f
+        _cleanup_set_free_free_ Set *locales = NULL;
8d419f
         _cleanup_strv_free_ char **l = NULL;
8d419f
         int r;
8d419f
 
8d419f
@@ -203,6 +203,9 @@ int get_locales(char ***ret) {
8d419f
         if (!l)
8d419f
                 return -ENOMEM;
8d419f
 
8d419f
+        /* Now, all elements are owned by strv 'l'. Hence, do not call set_free_free(). */
8d419f
+        locales = set_free(locales);
8d419f
+
8d419f
         r = getenv_bool("SYSTEMD_LIST_NON_UTF8_LOCALES");
8d419f
         if (r == -ENXIO || r == 0) {
8d419f
                 char **a, **b;