From 2fbe635a83a79f8889afec421ae3990ea106fb91 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 13 Sep 2012 22:30:26 +0200 Subject: macro: introduce _cleanup_free_ macro for automatic freeing of scoped vars and make use of it --- src/core/hostname-setup.c | 3 +-- src/core/load-fragment.c | 6 ++---- 2 files changed, 3 insertions(+), 6 deletions(-) (limited to 'src/core') diff --git a/src/core/hostname-setup.c b/src/core/hostname-setup.c index 25ea09c733..120024065a 100644 --- a/src/core/hostname-setup.c +++ b/src/core/hostname-setup.c @@ -67,7 +67,7 @@ static int read_distro_hostname(char **hn) { #if defined(TARGET_FEDORA) || defined(TARGET_ARCH) || defined(TARGET_GENTOO) || defined(TARGET_ALTLINUX) || defined(TARGET_MANDRIVA) || defined(TARGET_MAGEIA) int r; - FILE *f; + _cleanup_fclose_ FILE *f = NULL; assert(hn); @@ -114,7 +114,6 @@ static int read_distro_hostname(char **hn) { r = -ENOENT; finish: - fclose(f); return r; #elif defined(TARGET_SUSE) || defined(TARGET_SLACKWARE) diff --git a/src/core/load-fragment.c b/src/core/load-fragment.c index 482d28b795..1f3da70aca 100644 --- a/src/core/load-fragment.c +++ b/src/core/load-fragment.c @@ -1469,7 +1469,7 @@ int config_parse_unit_condition_path( Unit *u = data; bool trigger, negate; Condition *c; - char *p; + _cleanup_free_ char *p = NULL; assert(filename); assert(lvalue); @@ -1496,7 +1496,6 @@ int config_parse_unit_condition_path( c = condition_new(cond, p, trigger, negate); if (!c) return -ENOMEM; - free(p); LIST_PREPEND(Condition, conditions, u->conditions, c); return 0; @@ -1516,7 +1515,7 @@ int config_parse_unit_condition_string( Unit *u = data; bool trigger, negate; Condition *c; - char *s; + _cleanup_free_ char *s = NULL; assert(filename); assert(lvalue); @@ -1538,7 +1537,6 @@ int config_parse_unit_condition_string( c = condition_new(cond, s, trigger, negate); if (!c) return log_oom(); - free(s); LIST_PREPEND(Condition, conditions, u->conditions, c); return 0; -- cgit v1.2.3-54-g00ecf