Merge pull request #462 from bebehei/valgrind

Add valgrind to travis configuration and check for leaks
This commit is contained in:
Nikos Tsipinakis 2017-12-19 19:19:07 +02:00 committed by GitHub
commit 5a9f37b07f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 24 additions and 3 deletions

View File

@ -12,13 +12,14 @@ addons:
- libcairo2-dev - libcairo2-dev
- libnotify-dev - libnotify-dev
- libgtk-3-dev - libgtk-3-dev
- valgrind
dist: trusty dist: trusty
sudo: false sudo: false
language: c language: c
before_install: before_install:
- pip install --user cpp-coveralls - pip install --user cpp-coveralls
script: script:
- CFLAGS="-fprofile-arcs -ftest-coverage -Werror" make all dunstify test - CFLAGS="-fprofile-arcs -ftest-coverage -Werror" make all dunstify test-valgrind
- coveralls - coveralls
compiler: compiler:
- gcc - gcc

10
.valgrind.suppressions Normal file
View File

@ -0,0 +1,10 @@
{
xdgBaseDir_leak
# see https://github.com/devnev/libxdg-basedir/pull/6
Memcheck:Leak
fun:malloc
...
fun:xdgInitHandle
...
fun:main
}

View File

@ -44,10 +44,20 @@ dunst: ${OBJ} main.o
dunstify: dunstify.o dunstify: dunstify.o
${CC} ${CFLAGS} -o $@ dunstify.o ${LDFLAGS} ${CC} ${CFLAGS} -o $@ dunstify.o ${LDFLAGS}
.PHONY: test .PHONY: test test-valgrind
test: test/test test: test/test
cd test && ./test cd test && ./test
test-valgrind: test/test
cd ./test \
&& valgrind \
--suppressions=../.valgrind.suppressions \
--leak-check=full \
--show-leak-kinds=definite \
--errors-for-leak-kinds=definite \
--error-exitcode=123 \
./test
test/test: ${OBJ} ${TEST_OBJ} test/test: ${OBJ} ${TEST_OBJ}
${CC} ${CFLAGS} -o $@ ${TEST_OBJ} ${OBJ} ${LDFLAGS} ${CC} ${CFLAGS} -o $@ ${TEST_OBJ} ${OBJ} ${LDFLAGS}

View File

@ -29,9 +29,9 @@ char *string_replace_at(char *buf, int pos, int len, const char *repl)
tmp = buf; tmp = buf;
} else { } else {
tmp = g_malloc(size); tmp = g_malloc(size);
memcpy(tmp, buf, pos);
} }
memcpy(tmp, buf, pos);
memcpy(tmp + pos, repl, repl_len); memcpy(tmp + pos, repl, repl_len);
memmove(tmp + pos + repl_len, buf + pos + len, buf_len - (pos + len) + 1); memmove(tmp + pos + repl_len, buf + pos + len, buf_len - (pos + len) + 1);