Skip to content

Commit b2f0ed0

Browse files
committed
Enable full leak report and fix leaks.
1 parent 8aa53af commit b2f0ed0

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

.github/workflows/CITest.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ jobs:
177177
run: |
178178
sudo apt-get -y update
179179
sudo apt-get -y install valgrind
180-
valgrind cstest tests
180+
valgrind --leak-check=full cstest tests
181181
182182
- name: Comaptibility header generation
183183
# clang-format-17 is only available in Ubuntu 24.04

suite/cstest/src/cstest.c

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

77+
void cleanup_test_files()
78+
{
79+
if (!test_files) {
80+
return;
81+
}
82+
for (size_t k = 0; k < file_count; ++k) {
83+
cs_mem_free(test_files[0][k]);
84+
}
85+
if (test_files[0]) {
86+
cs_mem_free(test_files[0]);
87+
}
88+
cs_mem_free(test_files);
89+
}
90+
7791
int main(int argc, const char **argv)
7892
{
7993
if (argc < 2 || strcmp(argv[1], "-h") == 0 ||
@@ -87,6 +101,7 @@ int main(int argc, const char **argv)
87101
get_tfiles(argc, argv);
88102
if (!*test_files || file_count == 0) {
89103
fprintf(stderr, "Arguments are invalid. No files found.\n");
104+
cleanup_test_files();
90105
exit(EXIT_FAILURE);
91106
}
92107

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

97112
print_test_run_stats(&stats);
113+
cleanup_test_files();
98114
if (res == TEST_RUN_ERROR) {
99115
fprintf(stderr, "[!] An error occured.\n");
100116
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)