From 520ef2ed66d47bb81a55829a88dda81f62dc95e5 Mon Sep 17 00:00:00 2001 From: Justus Winter <4winter@informatik.uni-hamburg.de> Date: Fri, 20 Jun 2014 13:54:28 +0200 Subject: libdiskfs: fix reference counting of peropen objects Previously, peropen objects were created with a reference count of zero. Therefore, if diskfs_create_protid fails, passing such an object to diskfs_release_peropen would lead to a reference count underflow. * libdiskfs/peropen-make.c (diskfs_peropen_make): Initialize reference count to one. * libdiskfs/protid-make.c (diskfs_start_protid): And consume this reference on success. Update comment. (diskfs_create_protid): Update comment. * libdiskfs/diskfs.h: Update comments. * libdiskfs/io-duplicate.c (diskfs_S_io_duplicate): Adjust reference counting accordingly. * libdiskfs/io-reauthenticate.c (diskfs_S_io_reauthenticate): Likewise. * libdiskfs/io-restrict-auth.c (diskfs_S_io_restrict_auth): Likewise. * doc/hurd.texi (Diskfs Internals): Update accordingly. --- libdiskfs/protid-make.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'libdiskfs/protid-make.c') diff --git a/libdiskfs/protid-make.c b/libdiskfs/protid-make.c index 22aaa2e1..0b092994 100644 --- a/libdiskfs/protid-make.c +++ b/libdiskfs/protid-make.c @@ -20,7 +20,7 @@ #include /* Build and return in CRED a protid which has no user identification, for - peropen PO. */ + peropen PO. On success, consume a reference to PO. */ error_t diskfs_start_protid (struct peropen *po, struct protid **cred) { @@ -29,7 +29,7 @@ diskfs_start_protid (struct peropen *po, struct protid **cred) sizeof (struct protid), cred); if (! err) { - refcount_ref (&po->refcnt); + /* Consume a reference to po. */ (*cred)->po = po; (*cred)->shared_object = MACH_PORT_NULL; (*cred)->mapped = 0; @@ -56,7 +56,7 @@ diskfs_finish_protid (struct protid *cred, struct iouser *user) } /* Create and return a protid for an existing peropen PO in CRED for - USER. */ + USER. On success, consume a reference to PO. */ error_t diskfs_create_protid (struct peropen *po, struct iouser *user, struct protid **cred) -- cgit v1.2.3