]> nv-tegra.nvidia Code Review - linux-2.6.git/blobdiff - drivers/net/tun.c
tun: fix a crash bug and a memory leak
[linux-2.6.git] / drivers / net / tun.c
index bb8c72c79c6f31c9c932b2960df6a2c2f009a08e..a06ad55d949cd72a075e50751801169ba519403e 100644 (file)
@@ -358,6 +358,8 @@ static void tun_free_netdev(struct net_device *dev)
 {
        struct tun_struct *tun = netdev_priv(dev);
 
+       BUG_ON(!test_bit(SOCK_EXTERNALLY_ALLOCATED, &tun->socket.flags));
+
        sk_release_kernel(tun->socket.sk);
 }
 
@@ -1115,6 +1117,7 @@ static int tun_set_iff(struct net *net, struct file *file, struct ifreq *ifr)
                tun->flags = flags;
                tun->txflt.count = 0;
                tun->vnet_hdr_sz = sizeof(struct virtio_net_hdr);
+               set_bit(SOCK_EXTERNALLY_ALLOCATED, &tun->socket.flags);
 
                err = -ENOMEM;
                sk = sk_alloc(&init_net, AF_UNSPEC, GFP_KERNEL, &tun_proto);