From: Christian Brauner Date: Thu, 31 Aug 2017 21:08:28 +0000 (+0200) Subject: lxc-user-nic: free memory and check for error X-Git-Tag: lxc-2.1.0~9^2~19 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8424b4e14b7f5c34ed6229d1001cd766a6bdc648;p=thirdparty%2Flxc.git lxc-user-nic: free memory and check for error - check for error on ifindex retrieval - free allocated memory Signed-off-by: Christian Brauner --- diff --git a/src/lxc/lxc_user_nic.c b/src/lxc/lxc_user_nic.c index 1853e0412..7541e4b8a 100644 --- a/src/lxc/lxc_user_nic.c +++ b/src/lxc/lxc_user_nic.c @@ -453,6 +453,8 @@ static int get_mtu(char *name) int idx; idx = if_nametoindex(name); + if (idx < 0) + return -1; return netdev_get_mtu(idx); } @@ -1215,6 +1217,12 @@ int main(int argc, char *argv[]) exit(EXIT_FAILURE); } host_veth_ifidx = if_nametoindex(nicname); + if (!host_veth_ifidx) { + free(newname); + free(nicname); + usernic_error("Failed to get netdev index: %s\n", strerror(errno)); + exit(EXIT_FAILURE); + } /* Write names of veth pairs and their ifindeces to stout: * (e.g. eth0:731:veth9MT2L4:730)