[PATCH] error handling in rrd_client.c

Thorsten von Eicken <[email protected]>
Newsgroups gmane.comp.db.rrdtool.devel
Message-ID <[email protected]>
The patch below explicitly closes the connection on error in 
response_read. I've found it to get stuck otherwise.
     TvE

# diff -u rrd_client.c.orig rrd_client.c
--- rrd_client.c.orig   2010-03-29 17:03:57.000000000 +0000
+++ rrd_client.c        2010-04-20 22:10:28.000000000 +0000
@@ -371,14 +371,17 @@
    ret->lines_num = 0;

    buffer_ptr = fgets (buffer, sizeof (buffer), sh);
-  if (buffer_ptr == NULL)
+  if (buffer_ptr == NULL) {
+    close_connection();
      return (-3);
+  }
    chomp (buffer);

    ret->status = strtol (buffer, &ret->message, 0);
    if (buffer == ret->message)
    {
      response_free (ret);
+    close_connection();
      return (-4);
    }
    /* Skip leading whitespace of the status message */
@@ -396,6 +399,7 @@
    if (ret->lines == NULL)
    {
      response_free (ret);
+    close_connection();
      return (-5);
    }
    memset (ret->lines, 0, sizeof (char *) * ret->status);
@@ -407,6 +411,7 @@
      if (buffer_ptr == NULL)
      {
        response_free (ret);
+      close_connection();
        return (-6);
      }
      chomp (buffer);
@@ -415,6 +420,7 @@
      if (ret->lines[i] == NULL)
      {
        response_free (ret);
+      close_connection();
        return (-7);
      }
    }
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.