aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2023-07-30 13:49:29 +0200
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2023-09-08 22:42:52 +0200
commit4fd8b3538c7351ac39ea81533727a99ff3e4abb2 (patch)
treea055c03e1c1981dcb6b182bc57159857296753b6
parentd17046773702aad9cb3269a23ecd35f5a4a552ff (diff)
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 <david.oberhollenzer@sigma-star.at>
-rw-r--r--include/sqfs/predef.h10
1 files 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;