From c84a94883161073239c35d181e25823ff0454f68 Mon Sep 17 00:00:00 2001 From: Zbigniew Jędrzejewski-Szmek Date: Sun, 24 Mar 2013 19:09:19 -0400 Subject: Add _cleanup_globfree_ Fixes a memleak in error path in exec_context_load_environment. --- src/shared/util.c | 4 +--- src/shared/util.h | 4 +++- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'src/shared') diff --git a/src/shared/util.c b/src/shared/util.c index 2f66597de3..52867a1779 100644 --- a/src/shared/util.c +++ b/src/shared/util.c @@ -4322,7 +4322,7 @@ int in_group(const char *name) { } int glob_exists(const char *path) { - glob_t g; + glob_t _cleanup_globfree_ g = {}; int r, k; assert(path); @@ -4339,8 +4339,6 @@ int glob_exists(const char *path) { else r = errno ? -errno : -EIO; - globfree(&g); - return r; } diff --git a/src/shared/util.h b/src/shared/util.h index 4c4aed583e..bea43fc4bc 100644 --- a/src/shared/util.h +++ b/src/shared/util.h @@ -37,8 +37,8 @@ #include #include #include -#include +#include #include "macro.h" #include "time-util.h" @@ -539,6 +539,8 @@ static inline void journal_closep(sd_journal **j) { 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; -- cgit v1.2.3-54-g00ecf