X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fovs_stats.c;h=8309223b0243bec4874c486233f5394708965dab;hb=b4e3ffe8633858d01f00a8654823baa55ecf6288;hp=20b0dd1f0174fbd31104f837c82572f339bc4843;hpb=0eff2a882a9265fd59d4f7a265c6b6810acb0032;p=collectd.git diff --git a/src/ovs_stats.c b/src/ovs_stats.c index 20b0dd1f..8309223b 100644 --- a/src/ovs_stats.c +++ b/src/ovs_stats.c @@ -332,6 +332,7 @@ static int ovs_stats_update_bridge(yajl_val bridge) { if (br == NULL) { br = (bridge_list_t *)calloc(1, sizeof(bridge_list_t)); if (!br) { + pthread_mutex_unlock(&g_stats_lock); ERROR("%s: Error allocating memory for bridge", plugin_name); return -1; } @@ -789,7 +790,6 @@ static void ovs_stats_conn_terminate() { */ static int ovs_stats_plugin_config(oconfig_item_t *ci) { bridge_list_t *bridge; - char *br_name; for (int i = 0; i < ci->children_num; i++) { oconfig_item_t *child = ci->children + i; @@ -821,19 +821,22 @@ static int ovs_stats_plugin_config(oconfig_item_t *ci) { goto cleanup_fail; } /* get value */ - if ((br_name = strdup(child->values[j].value.string)) == NULL) { - ERROR("%s: strdup() copy bridge name fail", plugin_name); - goto cleanup_fail; - } + char const *br_name = child->values[j].value.string; if ((bridge = ovs_stats_get_bridge(g_monitored_bridge_list_head, br_name)) == NULL) { if ((bridge = calloc(1, sizeof(bridge_list_t))) == NULL) { ERROR("%s: Error allocating memory for bridge", plugin_name); goto cleanup_fail; } else { + char *br_name_dup = strdup(br_name); + if (br_name_dup == NULL) { + ERROR("%s: strdup() copy bridge name fail", plugin_name); + goto cleanup_fail; + } + pthread_mutex_lock(&g_stats_lock); /* store bridge name */ - bridge->name = br_name; + bridge->name = br_name_dup; bridge->next = g_monitored_bridge_list_head; g_monitored_bridge_list_head = bridge; pthread_mutex_unlock(&g_stats_lock);