From e985665d2d226cb42b52bfcad6fd5b1586ad57d7 Mon Sep 17 00:00:00 2001 From: Zbigniew Jędrzejewski-Szmek Date: Fri, 25 Jan 2013 10:33:07 -0500 Subject: Add _cleanup_pclose_ and fix mismatching pipe close opened by popen() Based-on-patch-by: Thomas Jarosch cppcheck reported: [src/bootchart/svg.c:791]: (error) Mismatching allocation and deallocation: f --- src/shared/macro.h | 1 + src/shared/util.c | 5 +++++ src/shared/util.h | 1 + 3 files changed, 7 insertions(+) (limited to 'src/shared') diff --git a/src/shared/macro.h b/src/shared/macro.h index 29d91392f8..b307dedaa8 100644 --- a/src/shared/macro.h +++ b/src/shared/macro.h @@ -196,6 +196,7 @@ static inline size_t IOVEC_INCREMENT(struct iovec *i, unsigned n, size_t k) { #define _cleanup_free_ __attribute__((cleanup(freep))) #define _cleanup_fclose_ __attribute__((cleanup(fclosep))) +#define _cleanup_pclose_ __attribute__((cleanup(pclosep))) #define _cleanup_close_ __attribute__((cleanup(closep))) #define _cleanup_closedir_ __attribute__((cleanup(closedirp))) #define _cleanup_umask_ __attribute__((cleanup(umaskp))) diff --git a/src/shared/util.c b/src/shared/util.c index 490399c910..969ef2bb90 100644 --- a/src/shared/util.c +++ b/src/shared/util.c @@ -5553,6 +5553,11 @@ void fclosep(FILE **f) { fclose(*f); } +void pclosep(FILE **f) { + if (*f) + pclose(*f); +} + void closep(int *fd) { if (*fd >= 0) close_nointr_nofail(*fd); diff --git a/src/shared/util.h b/src/shared/util.h index 202e15d481..223617c3ff 100644 --- a/src/shared/util.h +++ b/src/shared/util.h @@ -522,6 +522,7 @@ int get_home_dir(char **ret); void freep(void *p); void fclosep(FILE **f); +void pclosep(FILE **f); void closep(int *fd); void closedirp(DIR **d); void umaskp(mode_t *u); -- cgit v1.2.3-54-g00ecf