Merge branch 'collectd-4.10' into collectd-5.0 collectd-5.0.2
authorFlorian Forster <octo@collectd.org>
Sat, 21 Jan 2012 17:25:37 +0000 (18:25 +0100)
committerFlorian Forster <octo@collectd.org>
Sat, 21 Jan 2012 17:25:54 +0000 (18:25 +0100)
Change-Id: I8fea9338ac6490b2a76530a58c6bd36ec17d021a

ChangeLog
src/oracle.c

index 9ad049c..4642da9 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -16,6 +16,7 @@
          as the hostname, subsequent values in the same network packets could
          have ended up using the modified name rather than the original name.
          Thanks to Sebastian Harl for identifying the problem.
+       * oracle plugin: A memory leak has been fixed in the parameter handling.
        * python plugin: A memory leak has been fixed. Thanks to Sven Trenkel
          for fixing this bug!
 
          as the hostname, subsequent values in the same network packets could
          have ended up using the modified name rather than the original name.
          Thanks to Sebastian Harl for identifying the problem.
+       * oracle plugin: A memory leak has been fixed in the parameter handling.
        * python plugin: A memory leak has been fixed. Thanks to Sven Trenkel
          for fixing this bug!
 
index 0356749..ec45996 100644 (file)
@@ -1,6 +1,7 @@
 /**
  * collectd - src/oracle.c
- * Copyright (C) 2008,2009  Florian octo Forster
+ * Copyright (C) 2008,2009  noris network AG
+ * Copyright (C) 2012       Florian octo Forster
  *
  * This program is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License as published by the
@@ -41,7 +42,7 @@
  * affiliates. Other names may be trademarks of their respective owners.
  *
  * Authors:
- *   Florian octo Forster <octo at noris.net>
+ *   Florian octo Forster <octo at collectd.org>
  **/
 
 #include "collectd.h"
@@ -91,32 +92,44 @@ static void o_report_error (const char *where, /* {{{ */
   sb4 error_code;
   int status;
 
-  status = OCIErrorGet (eh, /* record number = */ 1,
-      /* sqlstate = */ NULL,
-      &error_code,
-      (text *) &buffer[0],
-      (ub4) sizeof (buffer),
-      OCI_HTYPE_ERROR);
-  buffer[sizeof (buffer) - 1] = 0;
-
-  if (status == OCI_SUCCESS)
+  /* An operation may cause / return multiple errors. Loop until we have
+   * handled all errors available. */
+  while (42)
   {
-    size_t buffer_length;
+    memset (buffer, 0, sizeof (buffer));
+    error_code = -1;
+
+    status = OCIErrorGet (eh, /* record number = */ 1,
+        /* sqlstate = */ NULL,
+        &error_code,
+        (text *) &buffer[0],
+        (ub4) sizeof (buffer),
+        OCI_HTYPE_ERROR);
+    buffer[sizeof (buffer) - 1] = 0;
+
+    if (status == OCI_NO_DATA)
+      return;
 
-    buffer_length = strlen (buffer);
-    while ((buffer_length > 0) && (buffer[buffer_length - 1] < 32))
+    if (status == OCI_SUCCESS)
     {
-      buffer_length--;
-      buffer[buffer_length] = 0;
-    }
+      size_t buffer_length;
 
-    ERROR ("oracle plugin: %s: %s failed: %s",
-        where, what, buffer);
-  }
-  else
-  {
-    ERROR ("oracle plugin: %s: %s failed. Additionally, OCIErrorGet failed with status %i.",
-        where, what, status);
+      buffer_length = strlen (buffer);
+      while ((buffer_length > 0) && (buffer[buffer_length - 1] < 32))
+      {
+        buffer_length--;
+        buffer[buffer_length] = 0;
+      }
+
+      ERROR ("oracle plugin: %s: %s failed: %s",
+          where, what, buffer);
+    }
+    else
+    {
+      ERROR ("oracle plugin: %s: %s failed. Additionally, OCIErrorGet failed with status %i.",
+          where, what, status);
+      return;
+    }
   }
 } /* }}} void o_report_error */
 
@@ -555,11 +568,15 @@ static int o_read_database_query (o_database_t *db, /* {{{ */
         &column_name, &column_name_length, OCI_ATTR_NAME, oci_error);
     if (status != OCI_SUCCESS)
     {
+      OCIDescriptorFree (oci_param, OCI_DTYPE_PARAM);
       o_report_error ("o_read_database_query", "OCIAttrGet (OCI_ATTR_NAME)",
           oci_error);
       continue;
     }
 
+    OCIDescriptorFree (oci_param, OCI_DTYPE_PARAM);
+    oci_param = NULL;
+
     /* Copy the name to column_names. Warning: The ``string'' returned by OCI
      * may not be null terminated! */
     memset (column_names[i], 0, DATA_MAX_NAME_LEN);
@@ -737,6 +754,7 @@ static int o_shutdown (void) /* {{{ */
   }
   
   OCIHandleFree (oci_env, OCI_HTYPE_ENV);
+  oci_env = NULL;
 
   udb_query_free (queries, queries_num);
   queries = NULL;