lxc-user-nic: free memory and check for error

- check for error on ifindex retrieval - free allocated memory Signed-off-by: 's avatarChristian Brauner <christian.brauner@ubuntu.com>
parent d0b915aa
...@@ -453,6 +453,8 @@ static int get_mtu(char *name) ...@@ -453,6 +453,8 @@ static int get_mtu(char *name)
int idx; int idx;
idx = if_nametoindex(name); idx = if_nametoindex(name);
if (idx < 0)
return -1;
return netdev_get_mtu(idx); return netdev_get_mtu(idx);
} }
...@@ -1215,6 +1217,12 @@ int main(int argc, char *argv[]) ...@@ -1215,6 +1217,12 @@ int main(int argc, char *argv[])
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
host_veth_ifidx = if_nametoindex(nicname); 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: /* Write names of veth pairs and their ifindeces to stout:
* (e.g. eth0:731:veth9MT2L4:730) * (e.g. eth0:731:veth9MT2L4:730)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment