return ENOBUFS;
} else if (!shash_is_empty(&dpif->changed_ports)) {
struct shash_node *node = shash_first(&dpif->changed_ports);
- *devnamep = xstrdup(node->name);
- shash_delete(&dpif->changed_ports, node);
+ *devnamep = shash_steal(&dpif->changed_ports, node);
return 0;
} else {
return EAGAIN;
*devnamep = NULL;
return EAGAIN;
} else {
- *devnamep = xstrdup(node->name);
- shash_delete(&monitor->changed_netdevs, node);
+ *devnamep = shash_steal(&monitor->changed_netdevs, node);
return 0;
}
}
}
}
+/* Deletes 'node' from 'sh' and frees the node's name. The caller is still
+ * responsible for freeing the node's data, if necessary. */
void
shash_delete(struct shash *sh, struct shash_node *node)
{
+ free(shash_steal(sh, node));
+}
+
+/* Deletes 'node' from 'sh'. Neither the node's name nor its data is freed;
+ * instead, ownership is transferred to the caller. Returns the node's
+ * name. */
+char *
+shash_steal(struct shash *sh, struct shash_node *node)
+{
+ char *name = node->name;
+
hmap_remove(&sh->map, &node->node);
- free(node->name);
free(node);
+ return name;
}
static struct shash_node *
void shash_add_assert(struct shash *, const char *, const void *);
void *shash_replace(struct shash *, const char *, const void *data);
void shash_delete(struct shash *, struct shash_node *);
+char *shash_steal(struct shash *, struct shash_node *);
struct shash_node *shash_find(const struct shash *, const char *);
void *shash_find_data(const struct shash *, const char *);
void *shash_find_and_delete(struct shash *, const char *);