Wiki page hash-tables.md changed with summary [prevent leaks in hash_set] by Xavi Artigas

This commit is contained in:
Xavi Artigas 2018-04-30 02:34:21 -07:00 committed by apache
parent 82629984a2
commit af3e5f95c2
1 changed files with 8 additions and 3 deletions

View File

@ -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``.