summaryrefslogtreecommitdiff
path: root/src/lauxlib.c
diff options
context:
space:
mode:
authorKyle Evans <kevans@FreeBSD.org>2020-10-16 13:04:28 +0000
committerKyle Evans <kevans@FreeBSD.org>2020-10-16 13:04:28 +0000
commit2a40e13a7afd87b1618335378c99577e73db3eb1 (patch)
tree56644c42d2166358369370d330bdacfea53b0cd4 /src/lauxlib.c
parentabe858c1d6e8bf7d7206b09ed715677ac63b5fca (diff)
Notes
Diffstat (limited to 'src/lauxlib.c')
-rw-r--r--src/lauxlib.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/src/lauxlib.c b/src/lauxlib.c
index 8bdada50a7eb1..ac68bd32da904 100644
--- a/src/lauxlib.c
+++ b/src/lauxlib.c
@@ -1011,8 +1011,13 @@ static void *l_alloc (void *ud, void *ptr, size_t osize, size_t nsize) {
free(ptr);
return NULL;
}
- else
- return realloc(ptr, nsize);
+ else { /* cannot fail when shrinking a block */
+ void *newptr = realloc(ptr, nsize);
+ if (newptr == NULL && ptr != NULL && nsize <= osize)
+ return ptr; /* keep the original block */
+ else /* no fail or not shrinking */
+ return newptr; /* use the new block */
+ }
}