Skip to content

Commit

Permalink
tap: fix memory leak on failure in net_init_tap()
Browse files Browse the repository at this point in the history
Commit 091a6b2 fixed most of the memory leaks in failure
paths in net_init_tap() reported by Coverity (CID 1356216),
but missed one. Fix it by deferring the allocation of
fds and vhost_fds until after the error check.

Signed-off-by: Peter Maydell <[email protected]>
Signed-off-by: Jason Wang <[email protected]>
  • Loading branch information
pm215 authored and jasowang committed Jan 20, 2017
1 parent a023b7a commit fac7d7b
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions net/tap.c
Original file line number Diff line number Diff line change
Expand Up @@ -788,8 +788,8 @@ int net_init_tap(const Netdev *netdev, const char *name,
return -1;
}
} else if (tap->has_fds) {
char **fds = g_new0(char *, MAX_TAP_QUEUES);
char **vhost_fds = g_new0(char *, MAX_TAP_QUEUES);
char **fds;
char **vhost_fds;
int nfds, nvhosts;

if (tap->has_ifname || tap->has_script || tap->has_downscript ||
Expand All @@ -801,6 +801,9 @@ int net_init_tap(const Netdev *netdev, const char *name,
return -1;
}

fds = g_new0(char *, MAX_TAP_QUEUES);
vhost_fds = g_new0(char *, MAX_TAP_QUEUES);

nfds = get_fds(tap->fds, fds, MAX_TAP_QUEUES);
if (tap->has_vhostfds) {
nvhosts = get_fds(tap->vhostfds, vhost_fds, MAX_TAP_QUEUES);
Expand Down

0 comments on commit fac7d7b

Please sign in to comment.