diff --git a/core/emperor.c b/core/emperor.c index 8a1dc2aa..5aae6ef1 100644 --- a/core/emperor.c +++ b/core/emperor.c @@ -817,7 +817,6 @@ void emperor_del(struct uwsgi_instance *c_ui) { while(attr) { struct uwsgi_dyn_dict *tmp = attr; attr = attr->next; - if (tmp->key) free(tmp->key); if (tmp->value) free(tmp->value); free(tmp); } @@ -2437,7 +2436,6 @@ void uwsgi_emperor_simple_do_with_attrs(struct uwsgi_emperor_scanner *ues, char while(attr) { struct uwsgi_dyn_dict *tmp = attr; attr = attr->next; - if (tmp->key) free(tmp->key); if (tmp->value) free(tmp->value); free(tmp); } @@ -2450,7 +2448,6 @@ void uwsgi_emperor_simple_do_with_attrs(struct uwsgi_emperor_scanner *ues, char while(attr) { struct uwsgi_dyn_dict *tmp = attr; attr = attr->next; - if (tmp->key) free(tmp->key); if (tmp->value) free(tmp->value); free(tmp); } diff --git a/plugins/emperor_mongodb/emperor_mongodb.cc b/plugins/emperor_mongodb/emperor_mongodb.cc index f6ef1ccb..865a8cf2 100644 --- a/plugins/emperor_mongodb/emperor_mongodb.cc +++ b/plugins/emperor_mongodb/emperor_mongodb.cc @@ -77,8 +77,17 @@ extern "C" void uwsgi_imperial_monitor_mongodb(struct uwsgi_emperor_scanner *ues if (strlen(socket_name) == 0) socket_name = NULL; struct uwsgi_dyn_dict *attrs = NULL; - char *attr_key = NULL; - char *attr_value = NULL; + struct uwsgi_string_list *e_attrs = uwsgi.emperor_collect_attributes; + while(e_attrs) { + const char *attr_value = p.getStringField(e_attrs->value); + if (strlen(attr_value) == 0) attr_value = NULL; + if (attr_value) { + // the value memory is always reallocated + char *value = uwsgi_str((char *)attr_value); + uwsgi_dyn_dict_new(&attrs, e_attrs->value, e_attrs->len, value, strlen(value)); + } + e_attrs = NULL; + } if (attrs) { // attrs will be freed in case of error