[rrd-developers] [PATCH 4 of 7] * Clean up rrd_graph

Peter Stamfest peter at stamfest.at
Mon Mar 7 20:28:06 CET 2011


# HG changeset patch
# User Peter Stamfest <peter at stamfest.at>
# Date 1299524578 -3600
# Node ID 5c2915ea1c62b764a97bdfa035371ce90ef2bc6e
# Parent  f19fcee1409c615c87f81e2cc223100f96afe3cd
* Clean up rrd_graph
  - avoid code duplication

diff --git a/src/rrd_graph.c b/src/rrd_graph.c
--- a/src/rrd_graph.c
+++ b/src/rrd_graph.c
@@ -848,9 +848,8 @@
                 im->gdes[i].data = im->gdes[ii].data;
                 im->gdes[i].data_first = 0;
                 skip = 1;
+                break;
             }
-            if (skip)
-                break;
         }
         if (!skip) {
             unsigned long ft_step = im->gdes[i].step;   /* ft_step will record what we got from fetch */
@@ -4002,34 +4001,25 @@
     char **argv)
 {
     image_desc_t im;
-    rrd_info_t *grinfo;
+    rrd_info_t *grinfo = NULL;
     char *old_locale;
     rrd_graph_init(&im);
-    /* a dummy surface so that we can measure text sizes for placements */
+
     old_locale = setlocale(LC_NUMERIC, NULL);
     setlocale(LC_NUMERIC, "C");
     rrd_graph_options(argc, argv, &im);
     if (rrd_test_error()) {
-        setlocale(LC_NUMERIC, old_locale); /* reenable locale */
-        rrd_info_free(im.grinfo);
-        im_free(&im);
-        return NULL;
+	goto out;
     }
 
     if (optind >= argc) {
-        setlocale(LC_NUMERIC, old_locale); /* reenable locale */
-        rrd_info_free(im.grinfo);
-        im_free(&im);
         rrd_set_error("missing filename");
-        return NULL;
+	goto out;
     }
 
     if (strlen(argv[optind]) >= MAXPATH) {
-        setlocale(LC_NUMERIC, old_locale); /* reenable locale */
         rrd_set_error("filename (including path) too long");
-        rrd_info_free(im.grinfo);
-        im_free(&im);
-        return NULL;
+	goto out;
     }
 
     strncpy(im.graphfile, argv[optind], MAXPATH - 1);
@@ -4043,17 +4033,13 @@
     setlocale(LC_NUMERIC, old_locale); /* reenable locale for rendering the graph */
 
     if (rrd_test_error()) {
-        rrd_info_free(im.grinfo);
-        im_free(&im);
-        return NULL;
+	goto out;
     }
 
     /* Everything is now read and the actual work can start */
 
     if (graph_paint(&im) == -1) {
-        rrd_info_free(im.grinfo);
-        im_free(&im);
-        return NULL;
+	goto out;
     }
 
 
@@ -4085,6 +4071,12 @@
         grinfo_push(&im, sprintf_alloc("image"), RD_I_BLO, img);
     }
     grinfo = im.grinfo;
+    im.grinfo = NULL;
+
+out:
+    setlocale(LC_NUMERIC, old_locale); /* reenable locale */
+    if (im.grinfo != NULL) 
+        rrd_info_free(im.grinfo);
     im_free(&im);
     return grinfo;
 }



More information about the rrd-developers mailing list