From 4fd8b3538c7351ac39ea81533727a99ff3e4abb2 Mon Sep 17 00:00:00 2001 From: David Oberhollenzer Date: Sun, 30 Jul 2023 13:49:29 +0200 Subject: Fix reference count of copied objects Always set the reference count to 1 after creating a copy of an object. Signed-off-by: David Oberhollenzer --- include/sqfs/predef.h | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/include/sqfs/predef.h b/include/sqfs/predef.h index 9e32b42..fbc6519 100644 --- a/include/sqfs/predef.h +++ b/include/sqfs/predef.h @@ -186,9 +186,13 @@ static SQFS_INLINE void *sqfs_drop(void *obj) */ static SQFS_INLINE void *sqfs_copy(const void *obj) { - if (((const sqfs_object_t *)obj)->copy != NULL) { - return ((const sqfs_object_t *)obj)-> - copy((const sqfs_object_t *)obj); + const sqfs_object_t *orig = (const sqfs_object_t *)obj; + + if (orig->copy != NULL) { + sqfs_object_t *copy = orig->copy(orig); + if (copy != NULL) + copy->refcount = 1; + return copy; } return NULL; -- cgit v1.2.3