[PATCH 4 of 7] * Clean up rrd_graph

Peter Stamfest <[email protected]>
Newsgroups gmane.comp.db.rrdtool.devel
Message-ID <[email protected]>
# HG changeset patch
# User Peter Stamfest <[email protected]>
# 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;
 }
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.