Code

write_http plugin: Be extra conservative in wh_reset_buffer().
authorFlorian Forster <octo@collectd.org>
Wed, 3 Aug 2016 19:35:36 +0000 (21:35 +0200)
committerFlorian Forster <octo@collectd.org>
Wed, 3 Aug 2016 19:43:58 +0000 (21:43 +0200)
This function is called from wh_callback_free() which is used to clean up after
?alloc() failures, so the "send_buffer" field may actually be NULL.

Issue: #1835

src/write_http.c

index 3d50be539b0141e8a3d75f6bc8bd49283d7574fe..ec538b6129dddf78e8093e10264f8b5e870df218 100644 (file)
@@ -95,6 +95,9 @@ static void wh_log_http_error (wh_callback_t *cb)
 
 static void wh_reset_buffer (wh_callback_t *cb)  /* {{{ */
 {
+        if ((cb == NULL) || (cb->send_buffer == NULL))
+                return;
+
         memset (cb->send_buffer, 0, cb->send_buffer_size);
         cb->send_buffer_free = cb->send_buffer_size;
         cb->send_buffer_fill = 0;
@@ -320,7 +323,8 @@ static void wh_callback_free (void *data) /* {{{ */
 
         cb = data;
 
-        wh_flush_nolock (/* timeout = */ 0, cb);
+        if (cb->send_buffer != NULL)
+                wh_flush_nolock (/* timeout = */ 0, cb);
 
         if (cb->curl != NULL)
         {