utils_db_query: Removed excessive calls of udb_result_finish_result() and udb_query_f...
authorPavel Rochnyack <pavel2000@ngs.ru>
Wed, 11 May 2016 21:37:02 +0000 (03:37 +0600)
committerPavel Rochnyack <pavel2000@ngs.ru>
Thu, 24 May 2018 05:33:19 +0000 (12:33 +0700)
src/utils_db_query.c

index 0d56ad4..61fe2e4 100644 (file)
@@ -338,22 +338,20 @@ static int udb_result_prepare_result(udb_result_t const *r, /* {{{ */
   if ((r == NULL) || (prep_area == NULL))
     return -EINVAL;
 
+#if COLLECT_DEBUG
+  assert(prep_area->ds == NULL);
+  assert(prep_area->instances_pos == NULL);
+  assert(prep_area->values_pos == NULL);
+  assert(prep_area->metadata_pos == NULL);
+  assert(prep_area->instances_buffer == NULL);
+  assert(prep_area->values_buffer == NULL);
+  assert(prep_area->metadata_buffer == NULL);
+#endif
+
 #define BAIL_OUT(status)                                                       \
-  prep_area->ds = NULL;                                                        \
-  sfree(prep_area->instances_pos);                                             \
-  sfree(prep_area->values_pos);                                                \
-  sfree(prep_area->metadata_pos);                                              \
-  sfree(prep_area->instances_buffer);                                          \
-  sfree(prep_area->values_buffer);                                             \
-  sfree(prep_area->metadata_buffer);                                           \
+  udb_result_finish_result(r, prep_area);                                      \
   return (status)
 
-  /* Make sure previous preparations are cleaned up. */
-  udb_result_finish_result(r, prep_area);
-  prep_area->instances_pos = NULL;
-  prep_area->values_pos = NULL;
-  prep_area->metadata_pos = NULL;
-
   /* Read `ds' and check number of values {{{ */
   prep_area->ds = plugin_get_ds(r->type);
   if (prep_area->ds == NULL) {
@@ -931,7 +929,13 @@ int udb_query_prepare_result(udb_query_t const *q, /* {{{ */
   if ((q == NULL) || (prep_area == NULL))
     return -EINVAL;
 
-  udb_query_finish_result(q, prep_area);
+#if COLLECT_DEBUG
+  assert(prep_area->column_num == 0);
+  assert(prep_area->host == NULL);
+  assert(prep_area->plugin == NULL);
+  assert(prep_area->db_name == NULL);
+  assert(prep_area->interval == 0);
+#endif
 
   prep_area->column_num = column_num;
   prep_area->host = strdup(host);