summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lauxlib.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/lauxlib.c b/lauxlib.c
index 8bdada50..097c3cf3 100644
--- a/lauxlib.c
+++ b/lauxlib.c
@@ -1011,8 +1011,13 @@ static void *l_alloc (void *ud, void *ptr, size_t osize, size_t nsize) {
1011 free(ptr); 1011 free(ptr);
1012 return NULL; 1012 return NULL;
1013 } 1013 }
1014 else 1014 else { /* cannot fail when shrinking a block */
1015 return realloc(ptr, nsize); 1015 void *newptr = realloc(ptr, nsize);
1016 if (newptr == NULL && ptr != NULL && nsize <= osize)
1017 return ptr; /* keep the original block */
1018 else /* no fail or not shrinking */
1019 return newptr; /* use the new block */
1020 }
1016} 1021}
1017 1022
1018 1023