Skip to content

Commit b2a182a

Browse files
doug-gilbertaxboe
authored andcommitted
sgl_alloc_order: fix memory leak
sgl_alloc_order() can fail when 'length' is large on a memory constrained system. When order > 0 it will potentially be making several multi-page allocations with the later ones more likely to fail than the earlier one. So it is important that sgl_alloc_order() frees up any pages it has obtained before returning NULL. In the case when order > 0 it calls the wrong free page function and leaks. In testing the leak was sufficient to bring down my 8 GiB laptop with OOM. Reviewed-by: Bart Van Assche <bvanassche@acm.org> Signed-off-by: Douglas Gilbert <dgilbert@interlog.com> Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent a48faeb commit b2a182a

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

lib/scatterlist.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,7 @@ struct scatterlist *sgl_alloc_order(unsigned long long length,
514514
elem_len = min_t(u64, length, PAGE_SIZE << order);
515515
page = alloc_pages(gfp, order);
516516
if (!page) {
517-
sgl_free(sgl);
517+
sgl_free_order(sgl, order);
518518
return NULL;
519519
}
520520

0 commit comments

Comments
 (0)