Fix leaks and double frees in eina_hash example

Summary:
Short-lived eina strings do not need to be explicitly deallocated.
The return value of eina_hash_set DOES need to be deallocated, though.

Reviewers: cedric, ajwillia.ms

Differential Revision: https://phab.enlightenment.org/D6006
This commit is contained in:
Xavi Artigas 2018-05-01 13:19:57 -04:00 committed by Mike Blumenkrantz
parent 4a8b562a40
commit 3e23c210cb
1 changed files with 6 additions and 2 deletions

View File

@ -30,7 +30,9 @@ _hash_create()
unsigned int i;
// let's create a simple hash with integers as keys
hash = eina_hash_int32_new(_entry_free_cb);
// No need to provide a free func since values are Short-Live Eina Strings
// (eina_slstr) which will deallocate themselves.
hash = eina_hash_int32_new(NULL);
// Add initial entries to our hash
for (i = 0; i < 10; i++)
@ -139,8 +141,10 @@ _phonebook_demo()
// Change the phone number for an entry
old_num = eina_hash_set(phone_book, lookup_name, strdup("+12 34 222-22222"));
if (old_num)
if (old_num) {
printf("Old number for %s was %s\n\n", lookup_name, old_num);
_entry_free_cb(old_num);
}
// Change the name (key) on an entry
eina_hash_move(phone_book, "Raul Seixas", "Alceu Valenca");