netfs_S_dir_lookup released NEWPI on each exit of the translator path,
and missed some: when making the port failed, it dereferenced a null
NEWPI; when asprintf of the translator's path failed, and when an
O_EXLOCK or O_SHLOCK open could not get its lock, the port leaked.
Release it at OUT, as libdiskfs's dir_lookup does, clearing it where
the translator vanished and the lookup goes on. In both, the release
of a successful open's port just before OUT is left to OUT as well.
---
libdiskfs/dir-lookup.c | 2 --
libnetfs/dir-lookup.c | 10 ++++------
2 files changed, 4 insertions(+), 8 deletions(-)
diff --git a/libdiskfs/dir-lookup.c b/libdiskfs/dir-lookup.c
index 5c787ccfe..60316a3f6 100644
--- a/libdiskfs/dir-lookup.c
+++ b/libdiskfs/dir-lookup.c
@@ -545,8 +545,6 @@ diskfs_S_dir_lookup (struct protid *dircred,
err = errno;
*retry_port = ports_get_right (newpi);
- ports_port_deref (newpi);
- newpi = 0;
}
out:
diff --git a/libnetfs/dir-lookup.c b/libnetfs/dir-lookup.c
index accc1cf1e..ccc420712 100644
--- a/libnetfs/dir-lookup.c
+++ b/libnetfs/dir-lookup.c
@@ -316,17 +316,14 @@ netfs_S_dir_lookup (struct protid *dircred,
if (complete_path != translator_path)
free(complete_path);
if (err)
- {
- ports_port_deref (newpi);
- goto out;
- }
+ goto out;
}
- ports_port_deref (newpi);
goto out;
}
ports_port_deref (newpi);
+ newpi = NULL;
/* ENOENT means there was a hiccup, and the translator vanished
while NP was unlocked inside fshelp_fetch_root; continue as
normal. */
@@ -491,7 +488,6 @@ netfs_S_dir_lookup (struct protid *dircred,
err = errno;
*retry_port = ports_get_right (newpi);
- ports_port_deref (newpi);
}
out:
@@ -499,6 +495,8 @@ netfs_S_dir_lookup (struct protid *dircred,
netfs_nput (np);
if (dnp)
netfs_nrele (dnp);
+ if (newpi)
+ ports_port_deref (newpi);
free (relpath);
return err;
}
--
2.56.0