From f9d64d5837e0aa7b46604d80bad3bf511be3f8ec Mon Sep 17 00:00:00 2001 From: Vissarion Fisikopoulos Date: Mon, 18 Sep 2023 11:40:08 +0300 Subject: [PATCH] Update lusol.c (CRAN valgrid issue) valgrind reporting a realloc(3) call with size = 0 --- R-proj/DESCRIPTION | 4 ++-- R-proj/src/Rproj_externals/lp_solve/lusol.c | 11 +++++++++++ cran_gen/NEWS.md | 4 ++++ 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/R-proj/DESCRIPTION b/R-proj/DESCRIPTION index 55424ed15..a8e178df9 100644 --- a/R-proj/DESCRIPTION +++ b/R-proj/DESCRIPTION @@ -12,8 +12,8 @@ Description: Provides an R interface for 'volesti' C++ package. 'volesti' comput for sampling, rounding and rotating polytopes. Moreover, 'volesti' provides algorithms for estimating copulas useful in computational finance. Methods implemented in 'volesti' are described in A. Chalkis and V. Fisikopoulos (2022) and references therein. -Version: 1.1.2-6 -Date: 2023-04-11 +Version: 1.1.2-7 +Date: 2023-10-18 Maintainer: Vissarion Fisikopoulos Depends: Rcpp (>= 0.12.17) Imports: methods, stats diff --git a/R-proj/src/Rproj_externals/lp_solve/lusol.c b/R-proj/src/Rproj_externals/lp_solve/lusol.c index 5573fe827..df43bdaa6 100644 --- a/R-proj/src/Rproj_externals/lp_solve/lusol.c +++ b/R-proj/src/Rproj_externals/lp_solve/lusol.c @@ -63,6 +63,17 @@ void *clean_realloc(void *oldptr, int width, int newsize, int oldsize) { newsize *= width; oldsize *= width; + /* this works around valgrind reporting a realloc(3) call with size = 0. + According to https://linux.die.net/man/3/realloc glibc frees the + memory in this case, and (maybe?) returns NULL: + > if size is equal to zero, and ptr is not NULL, then the call + > is equivalent to free(ptr). */ +#ifdef __linux__ + if (oldptr != NULL && newsize == 0) { + free(oldptr); + return NULL; + } +#endif oldptr = LUSOL_REALLOC(oldptr, newsize); if(newsize > oldsize) /* MEMCLEAR(oldptr+oldsize, newsize-oldsize); */ diff --git a/cran_gen/NEWS.md b/cran_gen/NEWS.md index e3329b9f9..da588978d 100644 --- a/cran_gen/NEWS.md +++ b/cran_gen/NEWS.md @@ -50,3 +50,7 @@ # volesti 1.1.2-6 - Fix UBSAN issues (lp_presolve) + +# volesti 1.1.2-7 + +- Fix valgrind reporting a realloc(3) call with size = 0 (lp_presolve)