Fixes a memleak in error path in exec_context_load_environment.
int k;
bool ignore = false;
char **p;
- glob_t pglob = {};
+ glob_t _cleanup_globfree_ pglob = {};
int count, n;
fn = *i;
}
if (!path_is_absolute(fn)) {
-
if (ignore)
continue;
/* Filename supports globbing, take all matching files */
errno = 0;
if (glob(fn, 0, NULL, &pglob) != 0) {
- globfree(&pglob);
if (ignore)
continue;
}
count = pglob.gl_pathc;
if (count == 0) {
- globfree(&pglob);
if (ignore)
continue;
continue;
strv_free(r);
- globfree(&pglob);
return k;
}
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;
}
int glob_exists(const char *path) {
- glob_t g;
+ glob_t _cleanup_globfree_ g = {};
int r, k;
assert(path);
else
r = errno ? -errno : -EIO;
- globfree(&g);
-
return r;
}
#include <sys/resource.h>
#include <stddef.h>
#include <unistd.h>
-#include <systemd/sd-journal.h>
+#include <systemd/sd-journal.h>
#include "macro.h"
#include "time-util.h"
sd_journal_close(*j);
}
+#define _cleanup_globfree_ __attribute__((cleanup(globfree)))
+
_malloc_ static inline void *malloc_multiply(size_t a, size_t b) {
if (_unlikely_(b == 0 || a > ((size_t) -1) / b))
return NULL;
static int glob_item(Item *i, int (*action)(Item *, const char *)) {
int r = 0, k;
- glob_t g = {};
+ glob_t _cleanup_globfree_ g = {};
char **fn;
errno = 0;
- if ((k = glob(i->path, GLOB_NOSORT|GLOB_BRACE, NULL, &g)) != 0) {
-
+ k = glob(i->path, GLOB_NOSORT|GLOB_BRACE, NULL, &g);
+ if (k != 0)
if (k != GLOB_NOMATCH) {
if (errno > 0)
errno = EIO;
log_error("glob(%s) failed: %m", i->path);
return -errno;
}
- }
- STRV_FOREACH(fn, g.gl_pathv)
- if ((k = action(i, *fn)) < 0)
+ STRV_FOREACH(fn, g.gl_pathv) {
+ k = action(i, *fn);
+ if (k < 0)
r = k;
+ }
- globfree(&g);
return r;
}