diff options
Diffstat (limited to 'libdimension/interior.c')
-rw-r--r-- | libdimension/interior.c | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/libdimension/interior.c b/libdimension/interior.c index 9f9201d..0accb79 100644 --- a/libdimension/interior.c +++ b/libdimension/interior.c @@ -26,8 +26,10 @@ dmnsn_interior * dmnsn_new_interior() { dmnsn_interior *interior = dmnsn_malloc(sizeof(dmnsn_interior)); - interior->ior = 1.0; - interior->free_fn = NULL; + interior->ior = 1.0; + interior->free_fn = NULL; + interior->refcount = dmnsn_malloc(sizeof(unsigned int)); + *interior->refcount = 1; return interior; } @@ -36,9 +38,14 @@ void dmnsn_delete_interior(dmnsn_interior *interior) { if (interior) { - if (interior->free_fn) { - (*interior->free_fn)(interior->ptr); + if (*interior->refcount <= 1) { + if (interior->free_fn) { + (*interior->free_fn)(interior->ptr); + } + free(interior->refcount); + free(interior); + } else { + --*interior->refcount; } - free(interior); } } |