Merge branch 'collectd-5.6' into collectd-5.7
[collectd.git] / src / snmp.c
index 6e26ad5..74068ec 100644 (file)
@@ -706,11 +706,11 @@ static int csnmp_config_add_host(oconfig_item_t *ci) {
 
   ssnprintf(cb_name, sizeof(cb_name), "snmp-%s", hd->name);
 
-  user_data_t ud = {.data = hd, .free_func = csnmp_host_definition_destroy};
-
-  status =
-      plugin_register_complex_read(/* group = */ NULL, cb_name, csnmp_read_host,
-                                   hd->interval, /* user_data = */ &ud);
+  status = plugin_register_complex_read(
+      /* group = */ NULL, cb_name, csnmp_read_host, hd->interval,
+      &(user_data_t){
+          .data = hd, .free_func = csnmp_host_definition_destroy,
+      });
   if (status != 0) {
     ERROR("snmp plugin: Registering complex read function failed.");
     csnmp_host_definition_destroy(hd);
@@ -1363,8 +1363,11 @@ static int csnmp_read_table(host_definition_t *host, data_definition_t *data) {
     }
 
     res = NULL;
-    /* snmp_sess_synch_response always frees our req PDU */
     status = snmp_sess_synch_response(host->sess_handle, req, &res);
+
+    /* snmp_sess_synch_response always frees our req PDU */
+    req = NULL;
+
     if ((status != STAT_SUCCESS) || (res == NULL)) {
       char *errstr = NULL;