Skip to content

Commit

Permalink
libxdp: Fix resource leaks
Browse files Browse the repository at this point in the history
Free resources associated with xdp_program and xdp_multiprog using
their respective destructor. Also fix a map_fd leak.

Signed-off-by: Hengqi Chen <chenhengqi@outlook.com>
  • Loading branch information
chenhengqi authored and tohojo committed Aug 31, 2022
1 parent f75767c commit 82628d8
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions lib/libxdp/libxdp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1173,7 +1173,7 @@ struct xdp_program *xdp_program__from_fd(int fd)

return xdp_prog;
err:
free(xdp_prog);
xdp_program__close(xdp_prog);
return ERR_PTR(err);
}

Expand Down Expand Up @@ -1819,8 +1819,8 @@ static int xdp_multiprog__fill_from_fd(struct xdp_multiprog *mp,
__u32 info_len, map_id = 0;
struct xdp_program *prog;
struct btf *btf = NULL;
int map_fd = -1;
int err = 0;
int map_fd;

if (!mp)
return -EINVAL;
Expand Down Expand Up @@ -1936,6 +1936,8 @@ static int xdp_multiprog__fill_from_fd(struct xdp_multiprog *mp,
mp->is_loaded = true;

out:
if (map_fd >= 0)
close(map_fd);
btf__free(btf);
return err;
}
Expand All @@ -1956,7 +1958,7 @@ static struct xdp_multiprog *xdp_multiprog__from_fd(int fd, int hw_fd,

return mp;
err:
free(mp);
xdp_multiprog__close(mp);
return ERR_PTR(err);
}

Expand Down

0 comments on commit 82628d8

Please sign in to comment.