From af3e5f95c2bb5afce63abb834713319569b70b3d Mon Sep 17 00:00:00 2001 From: Xavi Artigas Date: Mon, 30 Apr 2018 02:34:21 -0700 Subject: [PATCH] Wiki page hash-tables.md changed with summary [prevent leaks in hash_set] by Xavi Artigas --- pages/develop/guides/c/eina/hash-tables.md.txt | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/pages/develop/guides/c/eina/hash-tables.md.txt b/pages/develop/guides/c/eina/hash-tables.md.txt index 9650e192a..ff0cb886a 100644 --- a/pages/develop/guides/c/eina/hash-tables.md.txt +++ b/pages/develop/guides/c/eina/hash-tables.md.txt @@ -119,13 +119,18 @@ The ``eina_hash_set()`` function does the same work as ``eina_hash_modify()`` bu ```c char *old_phone = NULL; -char *phone = NULL; // Replace the phone number of Richard Strauss old_phone = eina_hash_modify(phone_book, "Richard Georg Strauss", strdup("+23 45 111-11111")); -phone = eina_hash_set(phone_book, "Philippe de Magalhães", strdup("+33 6 111-11111")); -eina_hash_set(phone_book, "Richard Georg Strauss", strdup("+23 45 111-117711")); +// ... +old_phone = eina_hash_set(phone_book, "Philippe de Magalhães", strdup("+33 6 111-11111")); +// ... +old_phone = eina_hash_set(phone_book, "Richard Georg Strauss", strdup("+23 45 111-117711")); +// ... ``` +> **NOTE**: +> Remember to check the return value of ``eina_hash_modify()`` and ``eina_hash_set()`` and free it if required, or you might be leaking the previous entry in the hash! + ### Change the key associated with data ### Use the ``eina_hash_move()`` function to change the key without freeing and creating a new entry . You need only pass the hash, the old key and the new key. If the operation succeeds, the function returns ``EINA_TRUE``, if not it returns ``EINA_FALSE``.