X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=lib%2Fshash.c;h=82791e31f76e77445ff2bf771df6eb78ee4c687d;hb=e1aff6f9f7103ee59e2501d3e6c705a685b20aeb;hp=8fd2eb18fcf83a10a244f61190c8ff908c1d6821;hpb=f2f7be8696e030dbe6f7c859c4e2bd76fd363036;p=openvswitch diff --git a/lib/shash.c b/lib/shash.c index 8fd2eb18..82791e31 100644 --- a/lib/shash.c +++ b/lib/shash.c @@ -167,12 +167,25 @@ shash_replace(struct shash *sh, const char *name, const void *data) } } +/* 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 * @@ -180,7 +193,7 @@ shash_find__(const struct shash *sh, const char *name, size_t hash) { struct shash_node *node; - HMAP_FOR_EACH_WITH_HASH (node, struct shash_node, node, hash, &sh->map) { + HMAP_FOR_EACH_WITH_HASH (node, node, hash, &sh->map) { if (!strcmp(node->name, name)) { return node; }