Remove the free assumption from libab_ref.

This commit is contained in:
Danila Fedorin 2018-04-21 17:05:51 -07:00
parent 5d3130d39d
commit d096e2155c
3 changed files with 11 additions and 2 deletions

View File

@ -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.
*/

View File

@ -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;

View File

@ -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) {