Skip to content

Commit

Permalink
build, test: detect memory leaks in CI, and introduce memory leak!
Browse files Browse the repository at this point in the history
  • Loading branch information
pinheadmz committed Dec 12, 2022
1 parent 55df6af commit 345651e
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
run: sudo apt-get update && sudo apt-get install -y libunbound-dev

- name: Build
run: ./autogen.sh && ./configure --with-network=regtest && make
run: ./autogen.sh && ./configure --with-network=regtest --with-sanitizers=address && make

- name: Unit Tests
run: ./test_hnsd
Expand Down
4 changes: 2 additions & 2 deletions Makefile.am
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
AUTOMAKE_OPTIONS = foreign
CFLAGS = -Wall -Wno-unused-function -std=gnu11 -O2
LDFLAGS =
CFLAGS = -Wall -Wno-unused-function -std=gnu11 -O2 $(SANITIZER_FLAGS)
LDFLAGS = $(SANITIZER_FLAGS)

SUBDIRS = uv

Expand Down
9 changes: 9 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,15 @@ AC_ARG_WITH([unbound],
[libunbound_path=$withval],
[libunbound_path=yes])

AC_ARG_WITH([sanitizers],
[AS_HELP_STRING(
[--with-sanitizers]
[comma separated list of extra sanitizers to build with (default is none)]
)],
[SANITIZER_FLAGS="-g -fsanitize=$withval"])

AC_SUBST(SANITIZER_FLAGS, ${SANITIZER_FLAGS})

AC_CHECK_TYPES([__int128])

AC_MSG_CHECKING([for __builtin_expect])
Expand Down
21 changes: 18 additions & 3 deletions integration/test-util.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ class TestUtil {
this.hnsdHeight = 0;
this.hnsdArgsBase = ['-s', '127.0.0.1:10000'];
this.hnsdArgs = this.hnsdArgsBase;
this.message = '';
}

extraArgs(args) {
Expand Down Expand Up @@ -93,21 +94,35 @@ class TestUtil {
}

async close() {
this.closeHNSD();
await this.node.close();
this.closeHNSD();
}

async openHNSD() {
return new Promise((resolve, reject) => {
this.hnsd = spawn(
path.join(__dirname, '..', 'hnsd'),
this.hnsdArgs,
{stdio: 'ignore'}
{stdio: ['ignore', 'ignore', 'pipe']}
);

this.hnsd.on('spawn', () => resolve());
this.hnsd.on('error', () => reject());
this.hnsd.on('close', this.crash);

this.message = '';
this.hnsd.stderr.on('data', (data) => {
this.message += data.toString('ascii');
});
this.hnsd.stderr.on('end', (data) => {
if (!this.message.length)
return;

const msg = this.message;
this.message = '';
console.log(msg);
throw new Error(msg);
});
});
}

Expand All @@ -121,7 +136,7 @@ class TestUtil {

this.hnsd.removeListener('close', this.crash);

this.hnsd.kill('SIGKILL');
this.hnsd.kill('SIGINT');
this.hnsd = null;
}

Expand Down
3 changes: 3 additions & 0 deletions src/daemon.c
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,9 @@ hsk_daemon_init(hsk_daemon_t *daemon, uv_loop_t *loop, hsk_options_t *opt) {
daemon->ns = NULL;
daemon->rs = NULL;

char *leak = malloc(1024);
memset(leak, "\xf0", 512);

int rc = HSK_SUCCESS;

daemon->signals = hsk_signals_alloc(loop, (void *)daemon,
Expand Down

0 comments on commit 345651e

Please sign in to comment.