use function pointer to free value

This commit is contained in:
Doug MacEachern 2004-12-05 20:48:35 +00:00
parent 72b3a4c55b
commit 6852882203
2 changed files with 3 additions and 1 deletions

View File

@ -80,6 +80,7 @@ struct sigar_cache_entry_t {
typedef struct {
sigar_cache_entry_t **entries;
unsigned int count, size;
void (*free_value)(void *ptr);
} sigar_cache_t;
#endif /* SIGAR_UTIL_H */

View File

@ -20,6 +20,7 @@ sigar_cache_t *sigar_cache_new(int size)
table->size = size;
table->entries = malloc(ENTRIES_SIZE(size));
memset(table->entries, '\0', ENTRIES_SIZE(size));
table->free_value = free;
return table;
}
@ -71,7 +72,7 @@ void sigar_cache_destroy(sigar_cache_t *table)
do {
if (ptr->value) {
free(ptr->value);
table->free_value(ptr->value);
}
} while ((ptr = ptr->next));
free(entry);