Previously if `fdalloc` failed to allocate a file descriptor, the
function would exit without decrementing the reference count on the
vfscore_file object, leading to a potential memory leak.
This change reorders operations to prevent this scenario.
Signed-off-by: Andrei Tatar <andrei@unikraft.io>
Reviewed-by: Delia Pavel <delia_maria.pavel@stud.acs.upb.ro>
Approved-by: Razvan Deaconescu <razvand@unikraft.io>
GitHub-Closes: #1074
{
int fd, ret = 0;
- fhold(fp);
-
fd = vfscore_alloc_fd();
if (fd < 0) {
ret = fd;
goto exit;
}
+ fhold(fp);
+
ret = vfscore_install_fd(fd, fp);
if (ret)
fdrop(fp);