diff options
author | Alexey Khoroshilov <khoroshilov@ispras.ru> | 2012-08-09 15:19:25 +0200 |
---|---|---|
committer | Jens Axboe <axboe@kernel.dk> | 2012-08-09 15:19:25 +0200 |
commit | 389d7b26d9e4f78b17366c23a3aa16b3c5cb3bde (patch) | |
tree | 7add3d139c36f1e367a5d120b2552e5daeb3bcdb | |
parent | 0676806707281e27b13d44323bed580a8160b7a4 (diff) | |
download | linux-3.10-389d7b26d9e4f78b17366c23a3aa16b3c5cb3bde.tar.gz linux-3.10-389d7b26d9e4f78b17366c23a3aa16b3c5cb3bde.tar.bz2 linux-3.10-389d7b26d9e4f78b17366c23a3aa16b3c5cb3bde.zip |
bio: Fix potential memory leak in bio_find_or_create_slab()
Do not leak memory by updating pointer with potentially NULL realloc return value.
Found by Linux Driver Verification project (linuxtesting.org).
Signed-off-by: Alexey Khoroshilov <khoroshilov@ispras.ru>
Acked-by: Jeff Moyer <jmoyer@redhat.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
-rw-r--r-- | fs/bio.c | 11 |
1 files changed, 6 insertions, 5 deletions
@@ -73,7 +73,7 @@ static struct kmem_cache *bio_find_or_create_slab(unsigned int extra_size) { unsigned int sz = sizeof(struct bio) + extra_size; struct kmem_cache *slab = NULL; - struct bio_slab *bslab; + struct bio_slab *bslab, *new_bio_slabs; unsigned int i, entry = -1; mutex_lock(&bio_slab_lock); @@ -97,11 +97,12 @@ static struct kmem_cache *bio_find_or_create_slab(unsigned int extra_size) if (bio_slab_nr == bio_slab_max && entry == -1) { bio_slab_max <<= 1; - bio_slabs = krealloc(bio_slabs, - bio_slab_max * sizeof(struct bio_slab), - GFP_KERNEL); - if (!bio_slabs) + new_bio_slabs = krealloc(bio_slabs, + bio_slab_max * sizeof(struct bio_slab), + GFP_KERNEL); + if (!new_bio_slabs) goto out_unlock; + bio_slabs = new_bio_slabs; } if (entry == -1) entry = bio_slab_nr++; |