Skip to content

Commit bb34e0d

Browse files
committed
Merge tag 'linux-kselftest-fixes-5.18-rc3' of git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest
Pull Kselftest fixes from Shuah Khan: "A mqueue perf test memory leak bug fix. mq_perf_tests failed to call CPU_FREE to free memory allocated by CPU_SET" * tag 'linux-kselftest-fixes-5.18-rc3' of git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest: testing/selftests/mqueue: Fix mq_perf_tests to free the allocated cpu set
2 parents e2dec48 + ce64763 commit bb34e0d

1 file changed

Lines changed: 17 additions & 8 deletions

File tree

tools/testing/selftests/mqueue/mq_perf_tests.c

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,9 @@ void shutdown(int exit_val, char *err_cause, int line_no)
180180
if (in_shutdown++)
181181
return;
182182

183+
/* Free the cpu_set allocated using CPU_ALLOC in main function */
184+
CPU_FREE(cpu_set);
185+
183186
for (i = 0; i < num_cpus_to_pin; i++)
184187
if (cpu_threads[i]) {
185188
pthread_kill(cpu_threads[i], SIGUSR1);
@@ -551,6 +554,12 @@ int main(int argc, char *argv[])
551554
perror("sysconf(_SC_NPROCESSORS_ONLN)");
552555
exit(1);
553556
}
557+
558+
if (getuid() != 0)
559+
ksft_exit_skip("Not running as root, but almost all tests "
560+
"require root in order to modify\nsystem settings. "
561+
"Exiting.\n");
562+
554563
cpus_online = min(MAX_CPUS, sysconf(_SC_NPROCESSORS_ONLN));
555564
cpu_set = CPU_ALLOC(cpus_online);
556565
if (cpu_set == NULL) {
@@ -589,7 +598,7 @@ int main(int argc, char *argv[])
589598
cpu_set)) {
590599
fprintf(stderr, "Any given CPU may "
591600
"only be given once.\n");
592-
exit(1);
601+
goto err_code;
593602
} else
594603
CPU_SET_S(cpus_to_pin[cpu],
595604
cpu_set_size, cpu_set);
@@ -607,7 +616,7 @@ int main(int argc, char *argv[])
607616
queue_path = malloc(strlen(option) + 2);
608617
if (!queue_path) {
609618
perror("malloc()");
610-
exit(1);
619+
goto err_code;
611620
}
612621
queue_path[0] = '/';
613622
queue_path[1] = 0;
@@ -622,17 +631,12 @@ int main(int argc, char *argv[])
622631
fprintf(stderr, "Must pass at least one CPU to continuous "
623632
"mode.\n");
624633
poptPrintUsage(popt_context, stderr, 0);
625-
exit(1);
634+
goto err_code;
626635
} else if (!continuous_mode) {
627636
num_cpus_to_pin = 1;
628637
cpus_to_pin[0] = cpus_online - 1;
629638
}
630639

631-
if (getuid() != 0)
632-
ksft_exit_skip("Not running as root, but almost all tests "
633-
"require root in order to modify\nsystem settings. "
634-
"Exiting.\n");
635-
636640
max_msgs = fopen(MAX_MSGS, "r+");
637641
max_msgsize = fopen(MAX_MSGSIZE, "r+");
638642
if (!max_msgs)
@@ -740,4 +744,9 @@ int main(int argc, char *argv[])
740744
sleep(1);
741745
}
742746
shutdown(0, "", 0);
747+
748+
err_code:
749+
CPU_FREE(cpu_set);
750+
exit(1);
751+
743752
}

0 commit comments

Comments
 (0)