core/socket: fix memleak in the error paths in usbffs_dispatch_eps()

This commit is contained in:
Yu Watanabe 2018-09-03 14:22:08 +09:00
parent f069ebfadd
commit 0de4876496
2 changed files with 14 additions and 8 deletions

2
TODO
View File

@ -1,7 +1,5 @@
Bugfixes: Bugfixes:
* the error paths in usbffs_dispatch_ep() leak memory
* copy.c: set the right chattrs before copying files and others after * copy.c: set the right chattrs before copying files and others after
External: External:

View File

@ -1359,8 +1359,10 @@ static int usbffs_dispatch_eps(SocketPort *p) {
n = (size_t) r; n = (size_t) r;
p->auxiliary_fds = new(int, n); p->auxiliary_fds = new(int, n);
if (!p->auxiliary_fds) if (!p->auxiliary_fds) {
return -ENOMEM; r = -ENOMEM;
goto clear;
}
p->n_auxiliary_fds = n; p->n_auxiliary_fds = n;
@ -1369,8 +1371,10 @@ static int usbffs_dispatch_eps(SocketPort *p) {
_cleanup_free_ char *ep = NULL; _cleanup_free_ char *ep = NULL;
ep = path_make_absolute(ent[i]->d_name, p->path); ep = path_make_absolute(ent[i]->d_name, p->path);
if (!ep) if (!ep) {
return -ENOMEM; r = -ENOMEM;
goto fail;
}
path_simplify(ep, false); path_simplify(ep, false);
@ -1379,16 +1383,20 @@ static int usbffs_dispatch_eps(SocketPort *p) {
goto fail; goto fail;
p->auxiliary_fds[k++] = r; p->auxiliary_fds[k++] = r;
free(ent[i]);
} }
return r; r = 0;
goto clear;
fail: fail:
close_many(p->auxiliary_fds, k); close_many(p->auxiliary_fds, k);
p->auxiliary_fds = mfree(p->auxiliary_fds); p->auxiliary_fds = mfree(p->auxiliary_fds);
p->n_auxiliary_fds = 0; p->n_auxiliary_fds = 0;
clear:
for (i = 0; i < n; ++i)
free(ent[i]);
return r; return r;
} }