Skip to content

Commit 56c7422

Browse files
committed
Fix leaks
1 parent f937bc8 commit 56c7422

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

suite/cstest/src/cstest.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,19 @@ void print_test_run_stats(const TestRunStats *stats)
7474
printf("\n");
7575
}
7676

77+
void cleanup_test_files() {
78+
if (!test_files) {
79+
return;
80+
}
81+
for (size_t k = 0; k < file_count; ++k) {
82+
cs_mem_free(test_files[0][k]);
83+
}
84+
if (test_files[0]) {
85+
cs_mem_free(test_files[0]);
86+
}
87+
cs_mem_free(test_files);
88+
}
89+
7790
int main(int argc, const char **argv)
7891
{
7992
if (argc < 2 || strcmp(argv[1], "-h") == 0 ||
@@ -87,6 +100,7 @@ int main(int argc, const char **argv)
87100
get_tfiles(argc, argv);
88101
if (!*test_files || file_count == 0) {
89102
fprintf(stderr, "Arguments are invalid. No files found.\n");
103+
cleanup_test_files();
90104
exit(EXIT_FAILURE);
91105
}
92106

@@ -95,6 +109,7 @@ int main(int argc, const char **argv)
95109
TestRunResult res = cstest_run_tests(*test_files, file_count, &stats);
96110

97111
print_test_run_stats(&stats);
112+
cleanup_test_files();
98113
if (res == TEST_RUN_ERROR) {
99114
fprintf(stderr, "[!] An error occured.\n");
100115
exit(EXIT_FAILURE);

suite/cstest/src/test_case.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,7 @@ void test_expected_compare(csh *handle, TestExpected *expected, cs_insn *insns,
248248

249249
#define CS_TEST_FAIL(msg) \
250250
_print_insn(handle, &insns[i]); \
251+
cs_free(insns, insns_count); \
251252
fail_msg(msg);
252253

253254
if (!compare_asm_text(asm_text, expec_data->asm_text,

0 commit comments

Comments
 (0)