Skip to content

Commit 30362a9

Browse files
committed
fix some memleaks in tests
These tests has forgott to call uc_close(uc), which lead to memory leaks. Found by the LeakSanitizer.
1 parent 8f5d0a0 commit 30362a9

File tree

4 files changed

+7
-0
lines changed

4 files changed

+7
-0
lines changed

tests/unit/test_arm.c

+2
Original file line numberDiff line numberDiff line change
@@ -905,6 +905,7 @@ static void test_arm_tcg_opcode_cmp(void)
905905
TEST_CHECK(cmp_info.v0 == 5 && cmp_info.v1 == 3);
906906
TEST_CHECK(cmp_info.pc == 0x1008);
907907
TEST_CHECK(cmp_info.size == 32);
908+
OK(uc_close(uc));
908909
}
909910

910911
static void test_arm_thumb_tcg_opcode_cmn(void)
@@ -931,6 +932,7 @@ static void test_arm_thumb_tcg_opcode_cmn(void)
931932
TEST_CHECK(cmp_info.v0 == 5 && cmp_info.v1 == 3);
932933
TEST_CHECK(cmp_info.pc == 0x1006);
933934
TEST_CHECK(cmp_info.size == 32);
935+
OK(uc_close(uc));
934936
}
935937

936938
static void test_arm_cp15_c1_c0_2(void)

tests/unit/test_arm64.c

+1
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,7 @@ static void test_arm64_mmu(void)
481481
TEST_CHECK(x1 == 0x4444444444444444);
482482
TEST_CHECK(x2 == 0x4444444444444444);
483483
free(data);
484+
OK(uc_close(uc));
484485
}
485486

486487
static void test_arm64_pc_wrap(void)

tests/unit/test_riscv.c

+1
Original file line numberDiff line numberDiff line change
@@ -718,6 +718,7 @@ static void test_riscv_mmu(void)
718718
OK(uc_mem_read(uc, data_address, &data_result, sizeof(data_result)));
719719

720720
TEST_CHECK(data_value == data_result);
721+
OK(uc_close(uc));
721722
}
722723

723724
static void test_riscv_priv(void)

tests/unit/test_x86.c

+3
Original file line numberDiff line numberDiff line change
@@ -1589,6 +1589,8 @@ static void test_x86_mmu(void)
15891589
OK(uc_mem_read(uc, 0x2000, &child, sizeof(child)));
15901590
TEST_CHECK(parrent == 60);
15911591
TEST_CHECK(child == 42);
1592+
OK(uc_context_free(context));
1593+
OK(uc_close(uc));
15921594
}
15931595

15941596
static bool test_x86_vtlb_callback(uc_engine *uc, uint64_t addr,
@@ -1632,6 +1634,7 @@ static void test_x86_segmentation(void)
16321634
OK(uc_open(UC_ARCH_X86, UC_MODE_64, &uc));
16331635
OK(uc_reg_write(uc, UC_X86_REG_GDTR, &gdtr));
16341636
uc_assert_err(UC_ERR_EXCEPTION, uc_reg_write(uc, UC_X86_REG_FS, &fs));
1637+
OK(uc_close(uc));
16351638
}
16361639

16371640
static void test_x86_0xff_lcall_callback(uc_engine *uc, uint64_t address,

0 commit comments

Comments
 (0)