]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
lxc-user-nic: free memory and check for error
authorChristian Brauner <christian.brauner@ubuntu.com>
Thu, 31 Aug 2017 21:08:28 +0000 (23:08 +0200)
committerChristian Brauner <christian.brauner@ubuntu.com>
Mon, 4 Sep 2017 11:19:19 +0000 (13:19 +0200)
- check for error on ifindex retrieval
- free allocated memory

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
src/lxc/lxc_user_nic.c

index 1853e0412c9acc8dfcd8df21f499090d86d7f090..7541e4b8a36d8f5f35dffad7af173c3403725fd4 100644 (file)
@@ -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)