use function pointer to free value
This commit is contained in:
parent
72b3a4c55b
commit
6852882203
|
@ -80,6 +80,7 @@ struct sigar_cache_entry_t {
|
||||||
typedef struct {
|
typedef struct {
|
||||||
sigar_cache_entry_t **entries;
|
sigar_cache_entry_t **entries;
|
||||||
unsigned int count, size;
|
unsigned int count, size;
|
||||||
|
void (*free_value)(void *ptr);
|
||||||
} sigar_cache_t;
|
} sigar_cache_t;
|
||||||
|
|
||||||
#endif /* SIGAR_UTIL_H */
|
#endif /* SIGAR_UTIL_H */
|
||||||
|
|
|
@ -20,6 +20,7 @@ sigar_cache_t *sigar_cache_new(int size)
|
||||||
table->size = size;
|
table->size = size;
|
||||||
table->entries = malloc(ENTRIES_SIZE(size));
|
table->entries = malloc(ENTRIES_SIZE(size));
|
||||||
memset(table->entries, '\0', ENTRIES_SIZE(size));
|
memset(table->entries, '\0', ENTRIES_SIZE(size));
|
||||||
|
table->free_value = free;
|
||||||
return table;
|
return table;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -71,7 +72,7 @@ void sigar_cache_destroy(sigar_cache_t *table)
|
||||||
|
|
||||||
do {
|
do {
|
||||||
if (ptr->value) {
|
if (ptr->value) {
|
||||||
free(ptr->value);
|
table->free_value(ptr->value);
|
||||||
}
|
}
|
||||||
} while ((ptr = ptr->next));
|
} while ((ptr = ptr->next));
|
||||||
free(entry);
|
free(entry);
|
||||||
|
|
Loading…
Reference in New Issue