]> granicus.if.org Git - sysstat/commitdiff
SVG: Free graphs structures only when all graphs have been drawn
authorSebastien GODARD <sysstat@users.noreply.github.com>
Wed, 24 Feb 2016 11:40:45 +0000 (12:40 +0100)
committerSebastien GODARD <sysstat@users.noreply.github.com>
Wed, 24 Feb 2016 11:40:45 +0000 (12:40 +0100)
Create a separate function to free structures.

Signed-off-by: Sebastien GODARD <sysstat@users.noreply.github.com>
svg_stats.c

index 6c102efdf3494090a702bb0e96e0ffdb36442686..19ecd3a3cddc5aed263b00485156624a921a0fa5 100644 (file)
@@ -335,6 +335,33 @@ long int xgrid(unsigned long timestart, unsigned long timeend)
        return ((timeend - timestart) / SVG_V_GRIDNR);
 }
 
+/*
+ ***************************************************************************
+ * Free global graphs structures.
+ *
+ * IN:
+ * @out                Pointer on array of chars for each graph definition.
+ * @outsize    Size of array of chars for each graph definition.
+ * @spmin      Array containing min values for graphs.
+ * @spmax      Array containing max values for graphs.
+ ***************************************************************************
+ */
+void free_graphs(char **out, int *outsize, double *spmin, double *spmax)
+{
+       if (out) {
+               free(out);
+       }
+       if (outsize) {
+               free(outsize);
+       }
+       if (spmin) {
+               free(spmin);
+       }
+       if (spmax) {
+               free(spmax);
+       }
+}
+
 /*
  ***************************************************************************
  * Display all graphs for current activity.
@@ -494,12 +521,6 @@ void draw_activity_graphs(struct activity *a, char *title[], char *g_title[], ch
 
        /* Next graph */
        (svg_p->graph_no) += a->g_nr;
-
-       /* Free remaining structures */
-       free(out);
-       free(outsize);
-       free(spmin);
-       free(spmax);
 }
 
 /*
@@ -556,6 +577,9 @@ __print_funct_t svg_print_pcsw_stats(struct activity *a, int curr, int action, s
        if (action & F_END) {
                draw_activity_graphs(a, title, g_title, NULL, group, spmin, spmax,
                                     out, outsize, svg_p, record_hdr);
+
+               /* Free remaining structures */
+               free_graphs(out, outsize, spmin, spmax);
        }
 }
 
@@ -638,5 +662,8 @@ __print_funct_t svg_print_paging_stats(struct activity *a, int curr, int action,
        if (action & F_END) {
                draw_activity_graphs(a, title, g_title, NULL, group, spmin, spmax,
                                     out, outsize, svg_p, record_hdr);
+
+               /* Free remaining structures */
+               free_graphs(out, outsize, spmin, spmax);
        }
 }