• Pavel Emelyanov's avatar
    [IPV4]: Fix memory leak in inet_hashtables.h when NUMA is on · 218ad12f
    Pavel Emelyanov authored
    The inet_ehash_locks_alloc() looks like this:
    
    #ifdef CONFIG_NUMA
    	if (size > PAGE_SIZE)
    		x = vmalloc(...);
    	else
    #endif
    		x = kmalloc(...);
    
    Unlike it, the inet_ehash_locks_alloc() looks like this:
    
    #ifdef CONFIG_NUMA
    	if (size > PAGE_SIZE)
    		vfree(x);
    	else
    #else
    		kfree(x);
    #endif
    
    The error is obvious - if the NUMA is on and the size
    is less than the PAGE_SIZE we leak the pointer (kfree is
    inside the #else branch).
    
    Compiler doesn't warn us because after the kfree(x) there's
    a "x = NULL" assignment, so here's another (minor?) bug: we 
    don't set x to NULL under certain circumstances.
    
    Boring explanation, I know... Patch explains it better.
    Signed-off-by: default avatarPavel Emelyanov <xemul@openvz.org>
    Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
    218ad12f
inet_hashtables.h 14.9 KB