1.1 --- a/ucx/map.c Tue May 19 17:01:28 2015 +0200 1.2 +++ b/ucx/map.c Thu Oct 15 12:34:10 2015 +0200 1.3 @@ -62,7 +62,7 @@ 1.4 return map; 1.5 } 1.6 1.7 -static void ucx_map_free_elmlist(UcxMap *map) { 1.8 +static void ucx_map_free_elmlist_contents(UcxMap *map) { 1.9 for (size_t n = 0 ; n < map->size ; n++) { 1.10 UcxMapElement *elem = map->map[n]; 1.11 if (elem != NULL) { 1.12 @@ -74,14 +74,20 @@ 1.13 } while (elem != NULL); 1.14 } 1.15 } 1.16 - alfree(map->allocator, map->map); 1.17 } 1.18 1.19 void ucx_map_free(UcxMap *map) { 1.20 - ucx_map_free_elmlist(map); 1.21 + ucx_map_free_elmlist_contents(map); 1.22 + alfree(map->allocator, map->map); 1.23 alfree(map->allocator, map); 1.24 } 1.25 1.26 +void ucx_map_clear(UcxMap *map) { 1.27 + ucx_map_free_elmlist_contents(map); 1.28 + memset(map->map, 0, map->size*sizeof(UcxMapElement*)); 1.29 + map->count = 0; 1.30 +} 1.31 + 1.32 int ucx_map_copy(UcxMap *restrict from, UcxMap *restrict to, 1.33 copy_func fnc, void *data) { 1.34 UcxMapIterator i = ucx_map_iterator(from); 1.35 @@ -124,7 +130,8 @@ 1.36 ucx_map_copy(&oldmap, map, NULL, NULL); 1.37 1.38 /* free the UcxMapElement list of oldmap */ 1.39 - ucx_map_free_elmlist(&oldmap); 1.40 + ucx_map_free_elmlist_contents(&oldmap); 1.41 + alfree(map->allocator, oldmap.map); 1.42 } 1.43 return 0; 1.44 }