summaryrefslogtreecommitdiff
path: root/src/core/locale-setup.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2013-10-01 00:08:30 +0200
committerLennart Poettering <lennart@poettering.net>2013-10-01 00:17:21 +0200
commitbcd8e6d1bd3f434af894faeb400fee0e99445a7f (patch)
tree1c0668d6b4e3bab3b2af0438525a62d318e2b37f /src/core/locale-setup.c
parent6c081276dc11722656906361ac78e415757865e3 (diff)
local: fix memory leak when putting together locale settings
Also, we need to use proper strv_env_xyz() calls when putting together the environment array, since otherwise settings won't be properly overriden. And let's get rid of strv_appendf(), is overkill and there was only one user.
Diffstat (limited to 'src/core/locale-setup.c')
-rw-r--r--src/core/locale-setup.c31
1 files changed, 27 insertions, 4 deletions
diff --git a/src/core/locale-setup.c b/src/core/locale-setup.c
index 31374ac644..276deb9dc1 100644
--- a/src/core/locale-setup.c
+++ b/src/core/locale-setup.c
@@ -29,6 +29,7 @@
#include "virt.h"
#include "fileio.h"
#include "strv.h"
+#include "env-util.h"
enum {
/* We don't list LC_ALL here on purpose. People should be
@@ -69,7 +70,7 @@ static const char * const variable_names[_VARIABLE_MAX] = {
};
int locale_setup(char ***environment) {
- char **env;
+ char **add;
char *variables[_VARIABLE_MAX] = {};
int r = 0, i;
@@ -119,22 +120,44 @@ int locale_setup(char ***environment) {
log_warning("Failed to read /etc/locale.conf: %s", strerror(-r));
}
+ add = NULL;
for (i = 0; i < _VARIABLE_MAX; i++) {
+ char *s;
+
if (!variables[i])
continue;
- env = strv_appendf(*environment, "%s=%s", variable_names[i], variables[i]);
- if (!env) {
+ s = strjoin(variable_names[i], "=", variables[i], NULL);
+ if (!s) {
+ r = -ENOMEM;
+ goto finish;
+ }
+
+ if (strv_push(&add, s) < 0) {
+ free(s);
+ r = -ENOMEM;
+ goto finish;
+ }
+ }
+
+ if (!strv_isempty(add)) {
+ char **e;
+
+ e = strv_env_merge(2, *environment, add);
+ if (!e) {
r = -ENOMEM;
goto finish;
}
- *environment = env;
+ strv_free(*environment);
+ *environment = e;
}
r = 0;
finish:
+ strv_free(add);
+
for (i = 0; i < _VARIABLE_MAX; i++)
free(variables[i]);