chiark / gitweb /
Revert "bootchart: use _cleanup_close_"
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 7 Mar 2013 20:28:03 +0000 (15:28 -0500)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 7 Mar 2013 20:35:50 +0000 (15:35 -0500)
This reverts commit 0ea9530d401827e299c6e04a433e69a7a2a89d80.

attribute(cleanup) can only be used inside functions (*of, sysfd
are leaked).

Cleanup functions are only called once when exiting scope (*f
is leaked twice).

src/bootchart/bootchart.c
src/bootchart/svg.c

index 0ad14dc37da97e0d31c00b4f71bdfd8834935e35..65f16c517c1b7cc9270dc48875101a9aa82cf899 100644 (file)
@@ -66,10 +66,10 @@ struct cpu_stat_struct cpustat[MAXCPUS];
 int pscount;
 int cpus;
 double interval;
 int pscount;
 int cpus;
 double interval;
-FILE _cleanup_fclose_ *of = NULL;
+FILE *of = NULL;
 int overrun = 0;
 static int exiting = 0;
 int overrun = 0;
 static int exiting = 0;
-int _cleanup_close_ sysfd=-1;
+int sysfd=-1;
 
 /* graph defaults */
 bool entropy = false;
 
 /* graph defaults */
 bool entropy = false;
@@ -106,7 +106,7 @@ int main(int argc, char *argv[])
         char datestr[200];
         time_t t = 0;
         const char *fn;
         char datestr[200];
         time_t t = 0;
         const char *fn;
-        _cleanup_fclose_ FILE *f = NULL;
+        _cleanup_fclose_ FILE *f;
         int gind;
         int i, r;
         char *init = NULL, *output = NULL;
         int gind;
         int i, r;
         char *init = NULL, *output = NULL;
@@ -378,8 +378,10 @@ int main(int argc, char *argv[])
         svg_do(build);
 
         fprintf(stderr, "systemd-bootchart wrote %s\n", output_file);
         svg_do(build);
 
         fprintf(stderr, "systemd-bootchart wrote %s\n", output_file);
+        fclose(of);
 
         closedir(proc);
 
         closedir(proc);
+        close(sysfd);
 
         /* nitpic cleanups */
         ps = ps_first;
 
         /* nitpic cleanups */
         ps = ps_first;
index 79476716a6bfe20563c9c06486c7043d0acc004b..9fee810795b30afb471d4a6fc40a54cba622aed1 100644 (file)
@@ -150,7 +150,7 @@ static void svg_title(const char *build)
         char date[256] = "Unknown";
         char cpu[256] = "Unknown";
         char *c;
         char date[256] = "Unknown";
         char cpu[256] = "Unknown";
         char *c;
-        FILE _cleanup_fclose_ *f = NULL;
+        FILE *f;
         time_t t;
         int fd;
         struct utsname uts;
         time_t t;
         int fd;
         struct utsname uts;
@@ -161,6 +161,7 @@ static void svg_title(const char *build)
         if (f) {
                 if (!fgets(cmdline, 255, f))
                         sprintf(cmdline, "Unknown");
         if (f) {
                 if (!fgets(cmdline, 255, f))
                         sprintf(cmdline, "Unknown");
+                fclose(f);
         }
 
         /* extract root fs so we can find disk model name in sysfs */
         }
 
         /* extract root fs so we can find disk model name in sysfs */
@@ -175,6 +176,7 @@ static void svg_title(const char *build)
                 if (f) {
                         if (!fgets(model, 255, f))
                                 fprintf(stderr, "Error reading disk model for %s\n", rootbdev);
                 if (f) {
                         if (!fgets(model, 255, f))
                                 fprintf(stderr, "Error reading disk model for %s\n", rootbdev);
+                        fclose(f);
                 }
         }
 
                 }
         }
 
@@ -196,6 +198,7 @@ static void svg_title(const char *build)
                                 break;
                         }
                 }
                                 break;
                         }
                 }
+                fclose(f);
         }
 
         svg("<text class=\"t1\" x=\"0\" y=\"30\">Bootchart for %s - %s</text>\n",
         }
 
         svg("<text class=\"t1\" x=\"0\" y=\"30\">Bootchart for %s - %s</text>\n",