Skip to contentSkip to conversation

selftests/cgroup: test_zswap: add missing NULL check after malloc()

PATCH New longlong yan 1 participant 1 message Jul 21

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

PATCH 1/1 selftests/cgroup: test_zswap: add missing NULL check after malloc()

In test_per_memcg_writeback(), zw_allocation is allocated via malloc() but its return value is not checked before being used in the subsequent memset() loop. If malloc() fails, this leads to a NULL pointer dereference.

Add the missing NULL check and jump to the existing error cleanup path. This is consistent with the wb_allocation check two lines below.

Fixes a19b47492751 ("selftest/cgroup: fix zswap test_no_invasive_cgroup_shrink on large pagesize system")
---
 tools/testing/selftests/cgroup/test_zswap.c | 2 ++
 1 file changed, 2 insertions(+)
tools/testing/selftests/cgroup/test_zswap.c +2 -0
index 49b36ee79160..9c2ff1b3c320 100644
@@ -479,6 +479,8 @@ static int test_no_invasive_cgroup_shrink(const char *root)
 	if (cg_enter_current(zw_group))
 		goto out;
 	zw_allocation = malloc(allocation_size);
+	if (!zw_allocation)
+		goto out;
 	for (int i = 0; i < nr_pages; i++) {
 		off = (unsigned long)i * page_size;
 		memset(&zw_allocation[off], 0, page_size);
Signature · 1 line
2.43.0