diff --git a/include/refcount.h b/include/refcount.h index ee0bea9..3339c3b 100644 --- a/include/refcount.h +++ b/include/refcount.h @@ -79,6 +79,11 @@ void libab_ref_free(libab_ref* ref); * Copies this reference, thereby increasing the reference count. */ void libab_ref_copy(const libab_ref* ref, libab_ref* into); +/** + * Function that can be passed in to refcount to simply use free + * when the refcount reaches 0. + */ +void libab_ref_data_free(void*); /** * Gets the value of the reference. */ diff --git a/src/parser.c b/src/parser.c index a6d8ba3..83f67dc 100644 --- a/src/parser.c +++ b/src/parser.c @@ -312,7 +312,10 @@ libab_result _parse_type_raw(struct parser_state* state, return result; } -void _parse_type_free(void* data) { libab_parsetype_free(data); } +void _parse_type_free(void* data) { + libab_parsetype_free(data); + free(data); +} libab_result _parse_type(struct parser_state* state, libab_ref* into) { libab_parsetype* store_into; diff --git a/src/refcount.c b/src/refcount.c index db7f7c1..d926161 100644 --- a/src/refcount.c +++ b/src/refcount.c @@ -31,7 +31,6 @@ void _libab_ref_changed(libab_ref* ref) { if (ref->count->free_func) { ref->count->free_func(ref->data); } - free(ref->data); } if (ref->count->weak == 0) { free(ref->count); @@ -58,6 +57,8 @@ void libab_ref_copy(const libab_ref* ref, libab_ref* into) { memcpy(into, ref, sizeof(*ref)); } +void libab_ref_data_free(void* data) { free(data); } + void* libab_ref_get(const libab_ref* ref) { void* to_return = NULL; if (ref->count->strong > 0) {