net: Trap attempts to call sock_kfree_s() with a NULL pointer.
authorDavid S. Miller <davem@davemloft.net>
Tue, 14 Oct 2014 21:02:37 +0000 (17:02 -0400)
committerDavid S. Miller <davem@davemloft.net>
Tue, 14 Oct 2014 21:02:37 +0000 (17:02 -0400)
Unlike normal kfree() it is never right to call sock_kfree_s() with
a NULL pointer, because sock_kfree_s() also has the side effect of
discharging the memory from the sockets quota.

Signed-off-by: David S. Miller <davem@davemloft.net>
net/core/sock.c

index b4f3ea2fce60cbb72d90434ad97ca26d682135a9..15e0c67b1069654af22ad9afe5c993cbcaafaec5 100644 (file)
@@ -1718,6 +1718,8 @@ EXPORT_SYMBOL(sock_kmalloc);
  */
 void sock_kfree_s(struct sock *sk, void *mem, int size)
 {
+       if (WARN_ON_ONCE(!mem))
+               return;
        kfree(mem);
        atomic_sub(size, &sk->sk_omem_alloc);
 }