Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds a memory leak check after running a unit test #1798

Open
wants to merge 2 commits into
base: unstable
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/unit/test_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "../util.h"
#include "../mt19937-64.h"
#include "../hashtable.h"
#include "../zmalloc.h"

/* We override the default assertion mechanism, so that it prints out info and then dies. */
void _serverAssert(const char *estr, const char *file, int line) {
Expand All @@ -28,6 +29,13 @@ int runTestSuite(struct unitTestSuite *test, int argc, char **argv, int flags) {
for (int id = 0; test->tests[id].proc != NULL; id++) {
test_num++;
int test_result = (test->tests[id].proc(argc, argv, flags) != 0);

/* Check if the test has cleaned up all the memory used. */
if (zmalloc_used_memory() > 0) {
printf("[" KRED "%s - %s" KRESET "] Memory leak detected of %zu bytes\n", test->tests[id].name, test->filename, zmalloc_used_memory());
test_result = 1;
}

if (!test_result) {
printf("[" KGRN "ok" KRESET "] - %s:%s\n", test->filename, test->tests[id].name);
} else {
Expand Down
Loading