aboutsummaryrefslogtreecommitdiffstats
path: root/reference
diff options
context:
space:
mode:
authorXavi Artigas <xavierartigas@yahoo.es>2018-05-01 13:19:57 -0400
committerMike Blumenkrantz <zmike@osg.samsung.com>2018-05-01 13:21:12 -0400
commit3e23c210cb2ab0a93a6fc8f5cbcf9c028628a681 (patch)
tree3eb54307a903b7600216b3e0afd5998b277ba75c /reference
parentUpdate examples after EFL API rename (diff)
downloadexamples-3e23c210cb2ab0a93a6fc8f5cbcf9c028628a681.tar.gz
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
Diffstat (limited to 'reference')
-rw-r--r--reference/c/eina/src/eina_hash.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/reference/c/eina/src/eina_hash.c b/reference/c/eina/src/eina_hash.c
index 986f54ea..e7a1f6e9 100644
--- a/reference/c/eina/src/eina_hash.c
+++ b/reference/c/eina/src/eina_hash.c
@@ -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");