diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2013-03-24 19:09:19 -0400 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2013-04-05 19:58:53 -0400 |
commit | c84a94883161073239c35d181e25823ff0454f68 (patch) | |
tree | 64c6fbf807493f3d878fa53113ba857116de7393 /src/core | |
parent | b92bea5d2a9481de69bb627a7b442a9f58fca43d (diff) |
Add _cleanup_globfree_
Fixes a memleak in error path in exec_context_load_environment.
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/execute.c | 12 |
1 files changed, 2 insertions, 10 deletions
diff --git a/src/core/execute.c b/src/core/execute.c index c51049767d..61369cdc93 100644 --- a/src/core/execute.c +++ b/src/core/execute.c @@ -1698,7 +1698,7 @@ int exec_context_load_environment(const ExecContext *c, char ***l) { int k; bool ignore = false; char **p; - glob_t pglob = {}; + glob_t _cleanup_globfree_ pglob = {}; int count, n; fn = *i; @@ -1709,7 +1709,6 @@ int exec_context_load_environment(const ExecContext *c, char ***l) { } if (!path_is_absolute(fn)) { - if (ignore) continue; @@ -1720,7 +1719,6 @@ int exec_context_load_environment(const ExecContext *c, char ***l) { /* Filename supports globbing, take all matching files */ errno = 0; if (glob(fn, 0, NULL, &pglob) != 0) { - globfree(&pglob); if (ignore) continue; @@ -1729,7 +1727,6 @@ int exec_context_load_environment(const ExecContext *c, char ***l) { } count = pglob.gl_pathc; if (count == 0) { - globfree(&pglob); if (ignore) continue; @@ -1743,7 +1740,6 @@ int exec_context_load_environment(const ExecContext *c, char ***l) { continue; strv_free(r); - globfree(&pglob); return k; } @@ -1755,16 +1751,12 @@ int exec_context_load_environment(const ExecContext *c, char ***l) { m = strv_env_merge(2, r, p); strv_free(r); strv_free(p); - - if (!m) { - globfree(&pglob); + if (!m) return -ENOMEM; - } r = m; } } - globfree(&pglob); } *l = r; |