Skip to content

Commit

Permalink
Update lusol.c (CRAN valgrid issue)
Browse files Browse the repository at this point in the history
valgrind reporting a realloc(3) call with size = 0
  • Loading branch information
vissarion authored Sep 18, 2023
1 parent 37d7c84 commit d0a1fe6
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions R-proj/src/Rproj_externals/lp_solve/lusol.c
Original file line number Diff line number Diff line change
Expand Up @@ -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); */
Expand Down

0 comments on commit d0a1fe6

Please sign in to comment.