chiark / gitweb /
Add _cleanup_pclose_ and fix mismatching pipe close opened by popen()
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Fri, 25 Jan 2013 15:33:07 +0000 (10:33 -0500)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Fri, 25 Jan 2013 15:38:42 +0000 (10:38 -0500)
Based-on-patch-by: Thomas Jarosch <thomas.jarosch@intra2net.com>
cppcheck reported:
[src/bootchart/svg.c:791]: (error) Mismatching allocation and deallocation: f

Makefile.am
src/bootchart/svg.c
src/shared/macro.h
src/shared/util.c
src/shared/util.h

index be3fa7140948d869cbd9bf591ae35e003fdc11a9..f362b5372834a41207eaf755a62c96426813bac1 100644 (file)
@@ -3084,6 +3084,9 @@ systemd_bootchart_SOURCES = \
        src/bootchart/log.c \
        src/bootchart/svg.c
 
+systemd_bootchart_LDADD = \
+       libsystemd-shared.la
+
 MANPAGES += \
        man/systemd-bootchart.1 \
        man/bootchart.conf.5
index 156918a94bf7f79e865b0f2dda57ead92f7e795f..b9636e20a34e2a61246c6d08bb85595ecacae614 100644 (file)
@@ -22,6 +22,8 @@
 #include <sys/utsname.h>
 
 #include "bootchart.h"
+#include "util.h"
+#include "macro.h"
 
 
 #define time_to_graph(t) ((t) * scale_x)
@@ -702,7 +704,7 @@ static int ps_filter(struct ps_struct *ps)
 
 static void svg_do_initcall(int count_only)
 {
-        FILE *f;
+        FILE _cleanup_pclose_ *f = NULL;
         double t;
         char func[256];
         int ret;
@@ -787,8 +789,6 @@ static void svg_do_initcall(int count_only)
 
                 kcount++;
         }
-
-        fclose(f);
 }
 
 
index 29d91392f8abc3848a3f454307ea9560f36a3a73..b307dedaa8bd6fc5fa379f5b715e6e97df7eaa0e 100644 (file)
@@ -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)))
index 490399c910876d5cfb0188ca22717ee90f06d5e8..969ef2bb90a759409178ff109c29bc2c11a740fa 100644 (file)
@@ -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);
index 202e15d481e7d0a7d1d11c7676d4b547e1c573bb..223617c3ff6284f17fc329ce1134cce98c402ff8 100644 (file)
@@ -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);