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/io-restrict-auth.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'libdiskfs/io-restrict-auth.c') diff --git a/libdiskfs/io-restrict-auth.c b/libdiskfs/io-restrict-auth.c index 011aa19e..80c0b208 100644 --- a/libdiskfs/io-restrict-auth.c +++ b/libdiskfs/io-restrict-auth.c @@ -41,6 +41,7 @@ diskfs_S_io_restrict_auth (struct protid *cred, return err; pthread_mutex_lock (&cred->po->np->lock); + refcount_ref (&cred->po->refcnt); err = diskfs_create_protid (cred->po, user, &newpi); if (! err) { @@ -48,6 +49,8 @@ diskfs_S_io_restrict_auth (struct protid *cred, *newportpoly = MACH_MSG_TYPE_MAKE_SEND; ports_port_deref (newpi); } + else + refcount_deref (&cred->po->refcnt); pthread_mutex_unlock (&cred->po->np->lock); iohelp_free_iouser (user); -- cgit v1.2.3