-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ci] [R-package] Fix memory leaks found by valgrind (#3443)
* fix int64 write error * attempt * [WIP] [ci] [R-package] Add CI job that runs valgrind tests * update all-successful * install * executable * fix redirect stuff * Apply suggestions from code review Co-authored-by: Guolin Ke <guolin.ke@outlook.com> * more flags * add mc to msvc proj * fix memory leak in mc * Update monotone_constraints.hpp * Update r_package.yml * remove R_INT64_PTR * disable openmp * Update gbdt_model_text.cpp * Update gbdt_model_text.cpp * Apply suggestions from code review * try to free vector * free more memories. * Update src/boosting/gbdt_model_text.cpp * fix using * try the UNPROTECT(1); * fix a const pointer * fix Common * reduce UNPROTECT * remove UNPROTECT(1); * fix null handle * fix predictor * use NULL after free * fix a leaking in test * try more fixes * test the effect of tests * throw exception in Fatal * add test back * Apply suggestions from code review * commet some tests * Apply suggestions from code review * Apply suggestions from code review * trying to comment out tests * Update openmp_wrapper.h * Apply suggestions from code review * Update configure * Update configure.ac * trying to uncomment * more comments * more uncommenting * more uncommenting * fix comment * more uncommenting * uncomment fully-commented out stuff * try uncommenting more dataset tests * uncommenting more tests * ok getting closer * more uncommenting * free dataset * skipping a test, more uncommenting * more skipping * re-enable OpenMP * allow on OpenMP thing * move valgrind to comment-only job * Apply suggestions from code review Co-authored-by: Nikita Titov <nekit94-08@mail.ru> * changes from code review * Apply suggestions from code review Co-authored-by: Nikita Titov <nekit94-08@mail.ru> * linting * issue comments too * remove issue_comment Co-authored-by: Guolin Ke <guolin.ke@outlook.com> Co-authored-by: Nikita Titov <nekit94-08@mail.ru>
- Loading branch information
1 parent
c182555
commit 81d7611
Showing
14 changed files
with
142 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
#!/bin/bash | ||
|
||
cd R-package/tests | ||
|
||
ALL_LOGS_FILE="out.log" | ||
VALGRIND_LOGS_FILE="valgrind-logs.log" | ||
|
||
RDvalgrind \ | ||
--no-readline \ | ||
--vanilla \ | ||
-d "valgrind --tool=memcheck --leak-check=full --track-origins=yes" \ | ||
-f testthat.R \ | ||
2>&1 > ${ALL_LOGS_FILE} || exit -1 | ||
|
||
cat ${ALL_LOGS_FILE} | ||
|
||
cat ${ALL_LOGS_FILE} | grep -E "^\=" > ${VALGRIND_LOGS_FILE} | ||
|
||
bytes_definitely_lost=$( | ||
cat ${VALGRIND_LOGS_FILE} \ | ||
| grep -E "definitely lost\: .*" \ | ||
| sed 's/^.*definitely lost\: \(.*\) bytes.*$/\1/' \ | ||
| tr -d "," | ||
) | ||
if [[ ${bytes_definitely_lost} -gt 0 ]]; then | ||
echo "valgrind found ${bytes_definitely_lost} bytes definitely lost" | ||
exit -1 | ||
fi | ||
|
||
bytes_indirectly_lost=$( | ||
cat ${VALGRIND_LOGS_FILE} \ | ||
| grep -E "indirectly lost\: .*" \ | ||
| sed 's/^.*indirectly lost\: \(.*\) bytes.*$/\1/' \ | ||
| tr -d "," | ||
) | ||
if [[ ${bytes_indirectly_lost} -gt 0 ]]; then | ||
echo "valgrind found ${bytes_indirectly_lost} bytes indirectly lost" | ||
exit -1 | ||
fi | ||
|
||
# one error caused by a false positive between valgrind and openmp is allowed | ||
# ==1312== 352 bytes in 1 blocks are possibly lost in loss record 146 of 2,458 | ||
# ==1312== at 0x483DD99: calloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so) | ||
# ==1312== by 0x40149CA: allocate_dtv (dl-tls.c:286) | ||
# ==1312== by 0x40149CA: _dl_allocate_tls (dl-tls.c:532) | ||
# ==1312== by 0x5702322: allocate_stack (allocatestack.c:622) | ||
# ==1312== by 0x5702322: pthread_create@@GLIBC_2.2.5 (pthread_create.c:660) | ||
# ==1312== by 0x56D0DDA: ??? (in /usr/lib/x86_64-linux-gnu/libgomp.so.1.0.0) | ||
# ==1312== by 0x56C88E0: GOMP_parallel (in /usr/lib/x86_64-linux-gnu/libgomp.so.1.0.0) | ||
# ==1312== by 0x154351B8: LGBM_DatasetCreateFromCSC (c_api.cpp:1286) | ||
# ==1312== by 0x1545789C: LGBM_DatasetCreateFromCSC_R (lightgbm_R.cpp:91) | ||
# ==1312== by 0x4941E2F: R_doDotCall (dotcode.c:634) | ||
# ==1312== by 0x494CCC6: do_dotcall (dotcode.c:1281) | ||
# ==1312== by 0x499FB01: bcEval (eval.c:7078) | ||
# ==1312== by 0x498B67F: Rf_eval (eval.c:727) | ||
# ==1312== by 0x498E414: R_execClosure (eval.c:1895) | ||
bytes_possibly_lost=$( | ||
cat ${VALGRIND_LOGS_FILE} \ | ||
| grep -E "possibly lost\: .*" \ | ||
| sed 's/^.*possibly lost\: \(.*\) bytes.*$/\1/' \ | ||
| tr -d "," | ||
) | ||
if [[ ${bytes_possibly_lost} -gt 352 ]]; then | ||
echo "valgrind found ${bytes_possibly_lost} bytes possibly lost" | ||
exit -1 | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
name: R valgrind tests | ||
|
||
on: | ||
pull_request_review_comment: | ||
types: [created] | ||
|
||
jobs: | ||
test-r-valgrind: | ||
name: r-package (ubuntu-latest, R-devel, valgrind) | ||
if: github.event.comment.body == '/gha run r-valgrind' && contains('OWNER,MEMBER,COLLABORATOR', github.event.comment.author_association) | ||
timeout-minutes: 120 | ||
runs-on: ubuntu-latest | ||
container: wch1/r-debug | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v1 | ||
with: | ||
fetch-depth: 5 | ||
submodules: true | ||
- name: Install packages | ||
shell: bash | ||
run: | | ||
RDscriptvalgrind -e "install.packages(c('R6', 'data.table', 'jsonlite', 'testthat'), repos = 'https://cran.r-project.org')" | ||
sh build-cran-package.sh | ||
RDvalgrind CMD INSTALL --preclean --install-tests lightgbm_*.tar.gz || exit -1 | ||
- name: Run tests with valgrind | ||
shell: bash | ||
run: ./.ci/test_r_package_valgrind.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters