Skip to contentSkip to conversation

sgl_alloc_order: memory leak

PATCH Superseded Douglas Gilbert 2 participants 2 messages Sep 20, 2020

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 sgl_alloc_order: memory leak

Noticed that when sgl_alloc_order() failed with order > 0 that free memory on my machine shrank. That function shouldn't call sgl_free() on its error path since that is only correct when order==0 .

---
 lib/scatterlist.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/scatterlist.c +1 -1
index 5d63a8857f36..c448642e0f78 100644
@@ -514,7 +514,7 @@ struct scatterlist *sgl_alloc_order(unsigned long long length,
 		elem_len = min_t(u64, length, PAGE_SIZE << order);
 		page = alloc_pages(gfp, order);
 		if (!page) {
-			sgl_free(sgl);
+			sgl_free_order(sgl, order);
 			return NULL;
 		}
 
Signature · 1 line
2.25.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 15 lines · Douglas Gilbert

Noticed that when sgl_alloc_order() failed with order > 0 that free memory on my machine shrank. That function shouldn't call sgl_free() on its error path since that is only correct when order==0 .

---
 lib/scatterlist.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/scatterlist.c +0 -0
index 5d63a8857f36..c448642e0f78 100644

lib/scatterlist.c struct scatterlist *sgl_alloc_order(unsigned long long length, · line 519

Quoted 7 lines
lib/scatterlist.c +1 -1
@@ -514,7 +514,7 @@ struct scatterlist *sgl_alloc_order(unsigned long long length,
 		elem_len = min_t(u64, length, PAGE_SIZE << order);
 		page = alloc_pages(gfp, order);
 		if (!page) {
-			sgl_free(sgl);
+			sgl_free_order(sgl, order);
 			return NULL;
 		}