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:
parent
4a8b562a40
commit
3e23c210cb
|
@ -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");
|
||||
|
|
Loading…
Reference in New Issue