Skip to content

Commit aa2c433

Browse files
authored
Merge pull request #1749 from ez-lbz/fix-node-name-map-duplicate
util: Fix duplicate node name map entries
2 parents a7453f8 + 70587e6 commit aa2c433

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

util/node_name_map.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ static int map_name(void *cxt, uint64_t guid, char *p)
6464
{
6565
cl_qmap_t *map = cxt;
6666
name_map_item_t *item;
67+
cl_map_item_t *inserted;
6768

6869
p = strtok(p, "\"#");
6970
if (!p)
@@ -74,7 +75,16 @@ static int map_name(void *cxt, uint64_t guid, char *p)
7475
return -1;
7576
item->guid = guid;
7677
item->name = strdup(p);
77-
cl_qmap_insert(map, item->guid, (cl_map_item_t *) item);
78+
if (!item->name) {
79+
free(item);
80+
return -1;
81+
}
82+
83+
inserted = cl_qmap_insert(map, item->guid, (cl_map_item_t *)item);
84+
if (inserted != (cl_map_item_t *)item) {
85+
free(item->name);
86+
free(item);
87+
}
7888
return 0;
7989
}
8090

0 commit comments

Comments
 (0)